Topic: Custom error messages
wavelytech
pro asked 7 years ago
Arkadiusz Idzikowski
staff answered 7 years ago
Closed
This topic is closed.
FREE CONSULTATION
Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.
Closed
- User: Pro
- Premium support: No
- Technology: MDB Angular
- MDB Version: -
- Device: -
- Browser: -
- OS: -
- Provided sample code: No
- Provided link: No
ak.leimrey pro commented 7 years ago
Well, your backend is responsible to return/throw a standardized error message. For that end I created a super trivial error-message service that accurately returns an error... Kinda like this showError(error: HttpErrorResponse) { if (error.status === 0) { this.toastService.error(An Unknown Error has occured); } else if (error.status === 400) { this.toastService.error(ErrorCode 400: Bad Request); } else if (error.status === 401) { this.toastService.error(ErrorCode 401: Unauthorized Request) } else if (error.status === 403) { this.toastService.error(ErrorCode 403: Forbidden); } else if (error.status === 404) { this.toastService.error(ErrorCode 404: Not found); } else if (error.status === 405) { this.toastService.error(ErrorCode 405: Method Not Allowed); } else if (error.status === 406) { this.toastService.error(ErrorCode 406: Not acceptable); } else if (error.status === 408) { this.toastService.error(ErrorCode 408: Request Timeout) } else if (error.status === 500) { this.toastService.error(ErrorCode 500: Internal Server Error); } else if (error.status === 501) { this.toastService.error(ErrorCode 501: Not implemented); } else if (error.status === 502) { this.toastService.error(ErrorCode 502: Bad Gateway); } else if (error.status === 503) { this.toastService.error(ErrorCode 503: Service Unavailable) } } handleError(error: HttpErrorResponse): ErrorObservable { return Observable.throw(${error.status}: ${error.statusText}; Request couldn't be processed!) }