Holiday Notice: Support will be provided on a limited scale from December 24th, 2024, to January 2nd, 2025. Happy holidays and a wonderful New Year!


Topic: Custom error messages

wavelytech pro asked 6 years ago


Hi I have an input, and I would like to set the error message on server side rather than typing it out. However, it is displaying the message "wrong" instead of showing "This is a test error message." as intended. Why is this so, and how do I fix it? TS: const testError = "This is a test error message.";   HTML <input type="text" name="name" id="name" class="form-control" data-error="{{testError}}" data-success=" " mdbInputValidate mdbInputDirectiveformControlName="name">

ak.leimrey pro commented 6 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!`) }

Arkadiusz Idzikowski staff answered 6 years ago


Dear wavylytech, Unfortunately, currently it is not possible to assign the variable with error messages. We need to fix something in input directive. Best, Arek

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Closed

Specification of the issue

  • ForumUser: Pro
  • Premium support: No
  • Technology: MDB Angular
  • MDB Version: -
  • Device: -
  • Browser: -
  • OS: -
  • Provided sample code: No
  • Provided link: No
Tags