Home > Mobile >  Rest API best practice to return exceptions [closed]
Rest API best practice to return exceptions [closed]

Time:09-17

I am building a Rest API. Do I need to raise an exception or return a string message?

What is the best practice in terms of returning exceptions to the client applications?

CodePudding user response:

There is no concept of an "exception" in an HTTP, they are a language feature. A REST API should report errors by returning an appropriate HTTP response code, for example 404 (Not Found).

CodePudding user response:

You should use appropriate HttpResponse code. Refer https://httpstatusdogs.com/ for more info on httpRespone code. About Exceptions, make sure you don't reveal too much info since it can be vulnerable.

  • Related