diff --git a/CHANGELOG.md b/CHANGELOG.md index a45477c6..10c3be16 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # CHANGE LOG +## [Prerelease] +- Add submit feedback error handling and new fields + ## [0.18.5] - Make NYPL footer sticky diff --git a/src/lib/api/FeedbackApi.ts b/src/lib/api/FeedbackApi.ts index b052eaf3..f149d47e 100644 --- a/src/lib/api/FeedbackApi.ts +++ b/src/lib/api/FeedbackApi.ts @@ -1,21 +1,29 @@ import appConfig from "~/config/appConfig"; import { Feedback } from "~/src/types/Feedback"; +import { log } from "../newrelic/NewRelic"; // TODO: disable feedback in development export const submitFeedback = async (feedback: Feedback) => { - return await fetch(appConfig.feedback.formURL, { - method: "POST", - headers: { - Authorization: `Bearer ${process.env.NEXT_PUBLIC_AIRTABLE_API_KEY}`, - "Content-Type": "application/json", - }, - body: JSON.stringify({ - fields: { - Feedback: feedback.feedback, - Category: feedback.category, - URL: feedback.url, + try { + return await fetch(appConfig.feedback.formURL, { + method: "POST", + headers: { + Authorization: `Bearer ${process.env.NEXT_PUBLIC_AIRTABLE_API_KEY}`, + "Content-Type": "application/json", }, - }), - }); + body: JSON.stringify({ + fields: { + Feedback: feedback.feedback, + Category: feedback.category, + Date: new Date().toLocaleDateString("en-US"), + Environment: process.env.APP_ENV, + URL: feedback.url, + }, + }), + }); + } catch (error) { + log(error, "Failed to submit feedback"); + throw new Error(`Failed to submit feedback: ${error.message}`); + } };