const { send, json } = require("micro");
const uncss = require("uncss");
const serializeError = require("serialize-error");
const Sentry = require('@sentry/node');

Sentry.init({ dsn: process.env.SENTRY_DSN });

module.exports = async (req, res) => {
  const data = await json(req, { limit: "14mb" });

  try {
    if (!data.inputHtml) throw new Error("Cannot process empty HTML");
    if (!data.inputCss) throw new Error("Cannot process empty CSS");

    const html = data.inputHtml.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi, "");

    uncss(
      html,
      {
        raw: data.inputCss,
        banner: false,
        ignoreSheets: [/./]
      },
      (error, output) => {
        Sentry.captureException(error);

        send(res, error ? 400 : 200, {
          outputCss: output,
          error: serializeError(error)
        });
      }
    );
  } catch (error) {
    Sentry.captureException(error);
    console.error(error);

    send(res, 400, {
      error: serializeError(error)
    });
  }
};

@@ -809,32 +809,40 @@
           error:
+ error ?
  serializeError(
@@ -843,24 +843,36 @@
 Error(error)
+ : undefined
 %0A        %7D);

Fix error handling