refactor: use RFC 7807 standard for error handling
All checks were successful
Build and Deploy Angular App / build (push) Successful in 1m30s
All checks were successful
Build and Deploy Angular App / build (push) Successful in 1m30s
This commit is contained in:
parent
10bf53adec
commit
eda6ca4b1a
@ -158,7 +158,7 @@ export default abstract class ApiService {
|
||||
|
||||
private handleError(error: HttpErrorResponse): void {
|
||||
// todo: change to Retry-After condition
|
||||
if (error.error && error.error.toString().includes("setup")) {
|
||||
if (error.error && error.error.detail.includes("setup")) {
|
||||
this.router.navigate(['/setup/']).then();
|
||||
return;
|
||||
}
|
||||
@ -167,6 +167,10 @@ export default abstract class ApiService {
|
||||
let message: string | undefined = undefined;
|
||||
if (error.error instanceof ErrorEvent) {
|
||||
title = `Произошла ошибка: ${error.error.message}`;
|
||||
} else {
|
||||
if (error.error && error.error.type && error.error.title) {
|
||||
title = error.error.title || `Ошибка с кодом ${error.status}`;
|
||||
message = error.error.detail || 'Неизвестная ошибка';
|
||||
} else {
|
||||
switch (error.status) {
|
||||
case 0:
|
||||
@ -195,11 +199,9 @@ export default abstract class ApiService {
|
||||
title = `Сервер вернул код ошибки: ${error.status}`;
|
||||
break;
|
||||
}
|
||||
if (error.error?.Error)
|
||||
message = error.error.Error;
|
||||
else if (error.error instanceof String)
|
||||
message = error.error.toString();
|
||||
else
|
||||
}
|
||||
|
||||
if (!message)
|
||||
message = error.error.statusMessage;
|
||||
}
|
||||
this.notify.error(message == '' ? undefined : message, title);
|
||||
|
Loading…
x
Reference in New Issue
Block a user