1
mirror of https://github.com/jakejarvis/jarv.is.git synced 2025-07-21 19:21:18 -04:00

add sentry to /api/contact

This commit is contained in:
2021-10-15 09:00:16 -04:00
parent 0b5c95ac42
commit f375699cfd

View File

@@ -1,3 +1,4 @@
import * as Sentry from "@sentry/node";
import fetch from "node-fetch";
import queryString from "query-string";
@@ -10,6 +11,11 @@ const HCAPTCHA_API_ENDPOINT = "https://hcaptcha.com/siteverify";
const { AIRTABLE_API_KEY, AIRTABLE_BASE } = process.env;
const AIRTABLE_API_ENDPOINT = `https://api.airtable.com/v0/`;
Sentry.init({
dsn: process.env.SENTRY_DSN || "",
environment: process.env.NODE_ENV || process.env.VERCEL_ENV || "",
});
export default async (req, res) => {
// disable caching on both ends
res.setHeader("Cache-Control", "private, no-cache, no-store, must-revalidate");
@@ -60,6 +66,13 @@ export default async (req, res) => {
const message = error instanceof Error ? error.message : "Unknown error.";
// don't log PEBCAK errors to sentry
if (message !== "missingData" && message !== "invalidCaptcha") {
// log error to sentry, give it 2 seconds to finish sending
Sentry.captureException(error);
await Sentry.flush(2000);
}
res.status(400).json({ success: false, message: message });
}
};