From 51ecb3c02e6c7c5d75e4f0c943c1362168760b8e Mon Sep 17 00:00:00 2001 From: Kyle Villegas <86266231+kylevillegas93@users.noreply.github.com> Date: Wed, 23 Oct 2024 10:34:44 -0400 Subject: [PATCH] SFR-2263: Add submit feedback error handling and audit data (#545) --- CHANGELOG.md | 3 +++ src/lib/api/FeedbackApi.ts | 34 +++++++++++++++++++++------------- 2 files changed, 24 insertions(+), 13 deletions(-) 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}`); + } };