Reputation: 11
I have created a REST api in .net core 2.1 and an angular front end initially in 7 but upgraded to 8 recently.
I have several post endpoints that are used to create new items (questions, answers, users, applications etc) the endpoints will take a json object and then run some validation rules against them. If the rules succeed then the object is saved to the database, if it fails it returns the modelstate errors and a 422 (have also tried 400) error along with the json response for example {"Address":["Please enter the address"],"TopLevelBudgetId":["Please select a top level budget"]}
However the error is always "OK"
.subscribe(
() => {
this.router.navigate([/administration/users
]);
},
error => {
console.log(error);
}));
in postman I can see the correct status code 422 and the json modelstate as shown above.
I have no idea where I have gone wrong whatsoever, followed various angular tutorials and have yet to find a solution.
I can see in the network tab of chrome tools that it first sends options and gets back a 204, this is because the sites locally on my machine are on different ports so it's handling CORS, and then it does the post correctly showing the 422 status code and the response.
Why do I only receive "OK" in the error handler
Upvotes: 0
Views: 410
Reputation: 11
so it was a schoolboy error on my part. I have an interceptor that handles 401/403 authentication errors and redirects to the login page.
This was the part that was at fault, didn't realise I had this interceptor as it was added near to the beginning of the development
const error = err.error.message || err.statusText; return throwError(error);
altered to rethrow the exception
return throwError(err);
Upvotes: 1