Friday 15 August 2014

rest - Asp.NET Web Api: Returning meaningful errors to client? -


I have created myself a standard ASP.NET Web API project and there is a post in it

Posts will basically put some value in a database, but before doing so I need to do several separate checks on an alternate database, if no one does not check, I want to return the customer to non-200 HAB status codes. Which one should I use?

What is the recommended status code to return? I would like to return some text with it, which will have additional information which can identify what was the error.

Or 200 and an additional JSOL payload has been recommended to identify if there was a problem and what

is there any example?

Thanks in advance

400 BadRequest can be used if you What is doing is the validation logic and this validation logic fails for some reason. As far as additional information is concerned, you can return some information in the body, for example, as a JSON payload:
  {"errorMessage": "Validation failed because the user The option is not present in the database "}   

If you are trying to update an entity that does not exist, you can also send a 404 status code.

No comments:

Post a Comment