Which HTTP status code is correct for Subscription cancel exception?

Tags: , , , ,



Which HTTP status code is correct for Subscription Canceled exception?

I need to throw an exception when the user tries to accesses a certain page.

I checked a few statuses like Payment Required, but it’s not satisfying the requirement. Any suggestion?

Answer

Which HTTP status code is correct for Subscription cancel exception?

HTTP status codes belong to the transfer documents over a network domain.

So the specifics of what is going on in your domain don’t particularly matter – the idea is to understand the error condition in terms of document transfer, and work from there.

In this case, the best fit is likely 403 Forbidden

The 403 (Forbidden) status code indicates that the server understood the request but refuses to authorize it. A server that wishes to make public why the request has been forbidden can describe that reason in the response payload (if any).

It may help to imagine how this example would play out on a web site. For the human user, you would return a bunch of HTML explaining that their subscription had been cancelled, perhaps with links to resources that would allow the user to re-subscribe, and so on.

For the browser, you would have the HTTP meta data, including the status code, so that the browser would understand the general purpose semantics of the message (for instance, should earlier representations of the resource be invalidated in the cache).

it’s a API request from front-end.

This doesn’t really enter into the discussion; the motivation for the uniform interface is that we can swap out the implementations at either end of the conversation and the semantics of the self descriptive messages don’t change.



Source: stackoverflow