Skip to content

Commit

Permalink
feat: adds logs to all endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
vivianedias committed Sep 12, 2024
1 parent 71b419f commit c93d153
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 18 deletions.
4 changes: 3 additions & 1 deletion src/app/check-eligibility/route.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { checkMatchEligibility } from "@/lib";
import { checkMatchEligibility, logger } from "@/lib";
import { getErrorMessage } from "@/utils";

export async function POST(request: Request) {
Expand All @@ -12,12 +12,14 @@ export async function POST(request: Request) {
const error = e as Record<string, unknown>;
if (error["name"] === "ValidationError") {
const errorMsg = `Validation error: ${getErrorMessage(error)}`;
logger.error(`[checkMatchEligibility] - 400: ${errorMsg}`);

return new Response(errorMsg, {
status: 400,
});
}

logger.error(`[checkMatchEligibility] - 500: ${getErrorMessage(error)}`);
return new Response(getErrorMessage(error), {
status: 500,
});
Expand Down
10 changes: 6 additions & 4 deletions src/app/cities/route.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type NextRequest } from "next/server";
import * as Yup from "yup";
import { db } from "@/lib";
import { db, logger } from "@/lib";
import { getErrorMessage } from "@/utils";

const stateParamsSchema = Yup.string().required().length(2);
Expand Down Expand Up @@ -30,16 +30,18 @@ export async function GET(request: NextRequest) {
const error = e as Record<string, unknown>;

if (error["name"] === "ValidationError") {
const errorMsg = `[citites] - Validation error: ${getErrorMessage(error)}`;
const errorMsg = `Validation error: ${getErrorMessage(error)}`;

logger.error(`[cities] - 400: ${errorMsg}`);

return new Response(errorMsg, {
status: 400,
});
}

const errorMsg = getErrorMessage(error);

return new Response(`[cities]: ${errorMsg}`, {
logger.error(`[cities] - 500: ${errorMsg}`);
return new Response(getErrorMessage(errorMsg), {
status: 500,
});
}
Expand Down
5 changes: 3 additions & 2 deletions src/app/db/upsert-msr/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { NextRequest } from "next/server";
import { upsertMsrOnDb } from "@/lib";
import { logger, upsertMsrOnDb } from "@/lib";
import { stringifyBigInt, getErrorMessage } from "@/utils";

export async function POST(request: NextRequest) {
Expand All @@ -12,12 +12,13 @@ export async function POST(request: NextRequest) {
const error = e as Record<string, unknown>;
if (error["name"] === "ValidationError") {
const errorMsg = `Validation error: ${getErrorMessage(error)}`;

logger.error(`[upsertMsrOnDb] - 400: ${errorMsg}`);
return new Response(errorMsg, {
status: 400,
});
}

logger.error(`[upsertMsrOnDb] - 500: ${getErrorMessage(error)}`);
return new Response(getErrorMessage(error), {
status: 500,
});
Expand Down
8 changes: 5 additions & 3 deletions src/app/geolocation/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { type NextRequest } from "next/server";
import * as Yup from "yup";
import { VOLUNTEER_API_URL } from "@/constants";
import { getErrorMessage } from "@/utils";
import { logger } from "@/lib";

const zipcodeParamSchema = Yup.string()
.required()
Expand Down Expand Up @@ -67,16 +68,17 @@ export async function GET(request: NextRequest) {
const error = e as Record<string, unknown>;

if (error["name"] === "ValidationError") {
const errorMsg = `[geolocation] - Validation error: ${getErrorMessage(error)}`;
const errorMsg = `Validation error: ${getErrorMessage(error)}`;
logger.error(`[geolocation] - 400: ${errorMsg}`);

return new Response(errorMsg, {
status: 400,
});
}

const errorMsg = getErrorMessage(error);

return new Response(`[geolocation]: ${errorMsg}`, {
logger.error(`[geolocation] - 400: ${errorMsg}`);
return new Response(getErrorMessage(error), {
status: 500,
});
}
Expand Down
3 changes: 3 additions & 0 deletions src/app/handle-request/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
upsertMsrOnDb,
checkMatchEligibility,
createMatch,
logger,
} from "@/lib";
import type { HandleRequestResponse } from "@/types";
import { getErrorMessage } from "@/utils";
Expand Down Expand Up @@ -187,11 +188,13 @@ export async function POST(request: Request) {
if (error["name"] === "ValidationError") {
const errorMsg = `Validation error: ${getErrorMessage(error)}`;

logger.error(`[checkMatchEligibility] - 400: ${errorMsg}`);
return new Response(errorMsg, {
status: 400,
});
}

logger.error(`[checkMatchEligibility] - 500: ${getErrorMessage(error)}`);
return new Response(getErrorMessage(error), {
status: 500,
});
Expand Down
5 changes: 4 additions & 1 deletion src/app/zendesk/ticket/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { NextRequest } from "next/server";
import { validateAndUpsertZendeskTicket } from "@/lib";
import { logger, validateAndUpsertZendeskTicket } from "@/lib";
import { getErrorMessage } from "@/utils";

export async function POST(request: NextRequest) {
Expand All @@ -20,10 +20,13 @@ export async function POST(request: NextRequest) {
if (error["name"] === "ValidationError") {
const errorMsg = `Validation error: ${getErrorMessage(error)}`;

logger.error(`[upsertZendeskTicket] - 400: ${errorMsg}`);
return new Response(errorMsg, {
status: 400,
});
}

logger.error(`[upsertZendeskTicket] - 500: ${getErrorMessage(error)}`);
return new Response(getErrorMessage(error), {
status: 500,
});
Expand Down
5 changes: 4 additions & 1 deletion src/app/zendesk/user/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { NextRequest } from "next/server";
import { validateAndUpsertZendeskUser } from "@/lib";
import { logger, validateAndUpsertZendeskUser } from "@/lib";
import { getErrorMessage } from "@/utils";

export async function POST(request: NextRequest) {
Expand All @@ -18,10 +18,13 @@ export async function POST(request: NextRequest) {
if (error["name"] === "ValidationError") {
const errorMsg = `Validation error: ${getErrorMessage(error)}`;

logger.error(`[upsertZendeskUser] - 400: ${errorMsg}`);
return new Response(errorMsg, {
status: 400,
});
}

logger.error(`[upsertZendeskUser] - 500: ${getErrorMessage(error)}`);
return new Response(getErrorMessage(error), {
status: 500,
});
Expand Down
6 changes: 5 additions & 1 deletion src/components/MultiStepForm/MultiStepFormWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
type StepChildrenProps,
type Values,
} from "@/types";
import { logger } from "@/lib";

interface MultiStepFormWrapperProps {
initialValues: Values;
Expand Down Expand Up @@ -81,7 +82,10 @@ export default function MultiStepFormWrapper({
setStatus(Status.idle);
nextStep(values);
} catch (error: any) {
console.error(error);
logger.error(error);
window.newrelic.noticeError(
Error("Something went wrong when submitting the form")
);
setStatus(Status.error);
}
};
Expand Down
3 changes: 2 additions & 1 deletion src/lib/createMatch.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { SupportRequests } from "@prisma/client";
import { MATCH_LAMBDA_URL } from "@/constants";
import { getErrorMessage } from "@/utils";
import logger from "./logger";

export default async function createMatch(
supportRequest: Omit<
Expand Down Expand Up @@ -48,7 +49,7 @@ export default async function createMatch(

return message;
} catch (e) {
console.error(
logger.error(
`[createMatch] - Something went wrong when creating a match for this support request '${
supportRequest.supportRequestId
}' for this user '${supportRequest.msrId}': ${getErrorMessage(e)}`
Expand Down
3 changes: 2 additions & 1 deletion src/lib/zendesk/upsertZendeskTicket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
} from "@/constants";
import { getErrorMessage, stringifyBigInt } from "@/utils";
import { ZendeskTicket } from "@/types";
import logger from "../logger";

export default async function upsertZendeskTicket(
ticket: Partial<ZendeskTicket>
Expand Down Expand Up @@ -35,7 +36,7 @@ export default async function upsertZendeskTicket(
ticketId: data.ticket.id,
};
} catch (e) {
console.error(
logger.error(
`[upsertZendeskTicket] - Something went wrong when upserting this ticket '${
ticket?.id ?? ""
}' for this user '${ticket.requester_id}': ${getErrorMessage(e)}`
Expand Down
3 changes: 2 additions & 1 deletion src/lib/zendesk/upsertZendeskUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
} from "../constants";
import { ZendeskUser } from "@/types";
import { getErrorMessage } from "@/utils";
import logger from "../logger";

export default async function upsertZendeskUser(user: ZendeskUser) {
try {
Expand Down Expand Up @@ -39,7 +40,7 @@ export default async function upsertZendeskUser(user: ZendeskUser) {

return { msrZendeskUserId };
} catch (e) {
console.error(
logger.error(
`[upsertZendeskUser] - Something went wrong when upserting this user on Zendesk '${
user.id ?? user.email
}': ${getErrorMessage(e)}`
Expand Down
4 changes: 2 additions & 2 deletions src/tests/integration/helpers/insert-support-requests.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { db } from "@/lib";
import { db, logger } from "@/lib";
import {
THERAPIST_ZENDESK_USER_ID,
LAWYER_ZENDESK_USER_ID,
Expand Down Expand Up @@ -74,7 +74,7 @@ export default async function insertSupportRequests(
}
}
} catch (error) {
console.error(
logger.error(
`[integration-tests]: Error while creating support requests or matches: ${getErrorMessage(error)}`
);
}
Expand Down

0 comments on commit c93d153

Please sign in to comment.