api status code for post request that has failed

JimmyShoe

I have an post api call that currently creates an appointment in my booking system.

If the api call sends the appointment request and the api can successfully create an appoinment the api returns a 201 created status code.

Currently if the appointment request is not created (due to various things such as the time is no longer available or the room is now being used) the api is returning a 400 bad request status code.

"400 Bad Request response status code indicates that the server cannot or will not process the request due to something that is perceived to be a client error"

The data sent is not invalid syntax and potentially could be resent and be successful.

Is there a more relevant status code for this failure to create a resource. would 422 Unprocessable Entity be a valid response in this case?

Ryan Carter

409 could suit this use-case(and my personal preference):

"The request could not be completed due to a conflict with the current state of the target resource. This code is used in situations where the user might be able to resolve the conflict and resubmit the request."

Typically used in PUT but could work in this scenario. For example, they could change the proposed time in the request. Or they could retry later if the room becomes available.

422 could also work to indicate a field level error.

Either way, an important thing is to accompany it with a good error message indicating the issue. From rfc7231:

the server SHOULD send a representation containing an explanation of the error situation, and whether it is a temporary or permanent condition. These status codes are applicable to any request method.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

React - axios.post error 'Request failed with status code 404'

request failed with status code 500 error in axios post method

Youtube API Uncaught (in promise) Error: Request failed with status code 403

React Native API fetch error Request failed with status code 400

Post request for bulk API is giving status code of 406, How to resolve it?

React Native Request failed with status code 400

Hyperledger sawtooth - Request failed with status code 429

Request failed with status code 429 Axios

Error Cypress: Request failed with status code 500

Request failed with status code 423 - React Project

Response for preflight has invalid HTTP status code 403 on angular post request

Getting "Request failed with status code 401" error when trying to create a playlist in Spotify using their API

OpenAI ChatGPT (GPT-3.5) API error 400: "Request failed with status code 400"

React and Express iTunes Search API :: Error: Request failed with status code 404

cURL Post request: get response and status code

Flutter - Handle status code 302 in POST request

Can 200 status code be response for POST request

I'm getting a ERROR Request failed with status code 404 AxiosError: Request failed with status code 404

axios get request Error: Request failed with status code 504

API status code for failed, previously started job

Axios catch error: Request failed with status code 404. Error while fetching post schema from my database

API request returning status code 404 not found

Getting Request failed with status code 403 with axios get

Request failed with status code 405 React Native Laravel

laravel5.8 Request failed with status code 500

Firebase Cloud Function Keep return "Request failed with status code 404"

AWS Lambda Create Function - Request failed with status code 403

AngularJS $http returns status code 0 from failed CORS request

Could not start backup:Request failed with status code 400 Google Cloud

TOP Ranking

HotTag

Archive