Skip to content

Commit

Permalink
feat: config route
Browse files Browse the repository at this point in the history
  • Loading branch information
truongnguyenptn committed Oct 14, 2023
1 parent af580db commit 6be7867
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,23 @@ export const getClientFilmDetailUrlById = (id: string) => {
return `${config.clientDomain}/film/${id}`
}

class CustomError extends Error {
constructor(message: string) {
super(message);
this.name = "CustomError";
}
}

interface ErrorResponse {
statusCode: number;
message: string[];
messageCode: string;
}

export function formatErrorMsg(error: ErrorResponse): string {
if (error.statusCode === 500 && error.messageCode === "INTERNAL_SERVER_ERROR" && error.message[0].includes("Cannot destructure property 'pubkey'")) {
throw new CustomError("Please log in.");
}
// Return a default message or throw an error if the error doesn't match the expected pattern
return "An unexpected error occurred.";
}

0 comments on commit 6be7867

Please sign in to comment.