Dherik
Dherik

Reputation: 19070

How I could return a "warning" as response in my REST API?

I'm trying to figure out how I could communicate to the client of my REST API a warning response, instead of an error or success.

I'm familiar with the practices to return error codes and the use of http status codes. Something like this:

{
   "status": 400,
   "code": 4000,
   "message": "Provided data not sufficient for insertion",
   "developerMessage": "Please verify that the feed is properly generated/set"
}

There a lot of examples on the internet explaining how the developer could handle response errors. But none of them talks about this "warning" case.

And what kind of warning is this?

Per example, when the user authenticate on my system, sometimes my API needs to inform the user that he needs to contact the support and confirm some informations before perform some actions in the system.

Another alternative is block the user in this specifics actions, returning an error and forget this warning case for now. But I think that will be necessary later, in another situation.

So, what the alternative for this case? What http status I can use? How to differ an error and a warning?

Thanks!

Upvotes: 0

Views: 1465

Answers (1)

Justinas Jakavonis
Justinas Jakavonis

Reputation: 8818

Per example, when the user authenticate on my system, sometimes my API needs to inform the user that he needs to contact the support and confirm some informations before perform some actions in the system

You should decide if user must confirm some information before accessing the specific resource or not. If user won't get error, it can ignore verification. I would use HTTP status code 403 Forbidden - the user might be logged in but does not have the necessary permissions for the resource (https://en.wikipedia.org/wiki/List_of_HTTP_status_codes) and specify exact reason in a message. Related discussion: HTTP status for "email not verified"

Upvotes: 1

Related Questions