From f5a58188cc53812e40c85a84c64fa7742022cedd Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sun, 17 Jul 2022 19:53:16 +0200 Subject: [PATCH] Handle unexpected API errors --- utils/api/throwables.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils/api/throwables.ts b/utils/api/throwables.ts index bba5abd..fb3f16d 100644 --- a/utils/api/throwables.ts +++ b/utils/api/throwables.ts @@ -65,7 +65,7 @@ export class Response { * @param defaultMessage - The message to display if the server is running in production mode and cannot display full error messages or if the error message cannot be determined. */ static fromUnknownError(obj: unknown, defaultMessage: string = "Unexpected server error occurred") { - if (process.env.NODE_ENV === "development") { + if (process.env.NODE_ENV !== "development") { return this.error({ message: defaultMessage }) } @@ -141,7 +141,7 @@ export class Response { e.consume(res) } else { - throw e + this.fromUnknownError(e).consume(res) } } }