feat(error-handling): Modified error-handling to show better types of errors

This commit is contained in:
Erik Tiekstra
2021-05-19 07:35:00 +02:00
parent 87bbc683ea
commit dc40953aba

View File

@@ -36,11 +36,20 @@ export class CustomError implements Error {
return error as any; 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 { export function errorToCustomError(error: Error): CustomError {
console.log(error); const type = CustomError.getErrorType(error);
const type = (error as any).type || ErrorType.UNKNOWN;
const message = error.message || (error as any); const message = error.message || (error as any);
const severity = ErrorSeverity.HIGH; const severity = ErrorSeverity.HIGH;