I have .net core 2.2 web api action which returns
return BadRequest(registerResult);
registerResult is IdentityResult type object.
This api is accessed with
return this.http.post(`${environment.apiUrl}/auth/register`, user);
from angular service.
I also have this, as http interceptor:
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
return next.handle(request).pipe(catchError(err => {
if (err.status === 401) {
// auto logout if 401 response returned from api
this.authenticationService.logout();
location.reload(true);
}
const error = err.error.message || err.statusText;
return throwError(error);
}));
}
Question is, how to return proper error messages from registerResult.Errors array, instead of "Bad request" or "Unknown error" which is currently returned?
First, you should return BadRequestObjectResult(registerResult)
and then, you should be able to access err.errors
array which contains all errors returned from registerResult object...
Эта статья взята из Интернета, укажите источник при перепечатке.
Если есть какие-либо нарушения, пожалуйста, свяжитесь с[email protected] Удалить.
я говорю два предложения