From dc40953aba3878b577d22630d0cc2e249a997abc Mon Sep 17 00:00:00 2001 From: Erik Tiekstra Date: Wed, 19 May 2021 07:35:00 +0200 Subject: [PATCH] feat(error-handling): Modified error-handling to show better types of errors --- .../src/app/data/models/error/custom-error.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/apps/dafa-web/src/app/data/models/error/custom-error.ts b/apps/dafa-web/src/app/data/models/error/custom-error.ts index 3da9600..14ca260 100644 --- a/apps/dafa-web/src/app/data/models/error/custom-error.ts +++ b/apps/dafa-web/src/app/data/models/error/custom-error.ts @@ -36,11 +36,20 @@ export class CustomError implements Error { return error as any; } } + + static getErrorType(error: Error): ErrorType { + let type = (error as any).type || ErrorType.UNKNOWN; + + if (error.name === 'HttpErrorResponse') { + type = ErrorType.API; + } + + return type; + } } export function errorToCustomError(error: Error): CustomError { - console.log(error); - const type = (error as any).type || ErrorType.UNKNOWN; + const type = CustomError.getErrorType(error); const message = error.message || (error as any); const severity = ErrorSeverity.HIGH;