Webclient with spring boot : Random occurrences of 400 bad request with the same type input data set - spring-webflux

I have list of input data ex(ids = 1,2,3,4,5,6...)I am trying to access those(urls like : https://localhost:8080/1) using webclient then it is giving 400 bad request for random ids like
In https://localhost:8080/1 sometimes I am getting bad request and proper response for the same as well as some times I am getting bad request https://localhost:8080/2 and getting proper response for the same. I am not understanding where it is going wrong. Can anyone help me with this, Thanks in advance

Related

postman giving 400 bad request when i use global varibales how to solve this

when i use normal json body postman gives me 201 created response but when i am using global variable postman giving me 400 bad request
Variables still need to be used in proper JSON format therefore you should be putting your strings in quotes:
{
"email": "{{email}}",
"password" : "{{password}}",
"confirmpassword" : "{{confirmpassword}}"
}
See https://learning.postman.com/docs/sending-requests/variables/
Side note: please provide actual "happy path" (when it worked) as well as your errors. Text instead of images is good too to help people try to reproduce your errors without a lot of typing

Http status code when data not found in Database

I'm trying to understand which Http Status Code to use in the following use case
The user tries to do a GET on an endpoint with an input ID.
The requested data is not available in the database.
Should the service send back:
404 - Not Found
As the data is NOT FOUND in the database
400 - Bad Request
As the data in the input request is not valid or present in the db
200 - OK with null response
200 - OK with an error message
In this case we can use a standard error message, with a contract that spans across all the 200 OK responses (like below).
BaseResponse {
Errors [{
Message: "Data Not Found"
}],
Response: null
}
Which is the right (or standard) approach to follow?
Thanks in advance.
Which is the right (or standard) approach to follow?
If you are following the REST API Architecture, you should follow these guidelines:
400 The request could not be understood by the server due to incorrect syntax. The client SHOULD NOT repeat the request without modifications.
It means that you received a bad request data, like an ID in alphanumeric format when you want only numeric IDs. Typically it refers to bad input formats or security checks (like an input array with a maxLength)
404 The server can not find the requested resource.
The ID format is valid and you can't find the resource in the data source.
If you don't follow any standard architecture, you should define how you want to manage these cases and share your thought with the team and customers.
In many legacy applications, an HTTP status 200 with errors field is very common since very-old clients were not so good to manage errors.

Identify bad requests(4xx response code) from navigator.sendBeacon()

How can I get response code from navigator.sendBeacon? I need to have some indicator that can say me that request is failed? Particularly, I am looking for a way to identify bad request (request that was send with “bad” malformed json and got 4xx response code). Is there any way to do it while using sendBeacon?
From documentation:
The sendBeacon() method returns true if the user agent is able to
successfully queue the data for transfer, Otherwise it returns false.
So, it is not returning false if request is invalid.(and response code is 4xx)
navigator.sendBeacon(that.sushiEndpoint, sushiPayload)

400 error message when trying to create a new document in CouchDb using XMLHttpRequest

I am trying to create a new document in a couchDB database but with the following code I get a '400 bad request' response. I want to create a document that does not contain any other information than the _id (and of course the generated _rev).
var xhrCreate = new XMLHttpRequest();
xhrCreate.open('PUT','http://domainName:5984/dbName/docName/', true);
xhrCreate.setRequestHeader("Content-type", "application/json");
xhrCreate.send();
The CouchDb documentation says that a 400 error indicates a:
"Bad request structure. The error can indicate an error with the request URL, path or headers. Differences in the supplied MD5 hash and content also trigger this error, as this may indicate message corruption."
Could anyone point me in the right direction? Hints and help is much appreciated.
CouchDB requires an empty document as part of the content:
xhrCreate.send('{}');

Is it okay to specify exactly why you are sending an HTTP error code?

If you run an API server then a client sends a bad request, you would usually send him 400 Bad Request error but is it acceptable if you change the message to a more specific one?
Example:
400 Invalid ID
400 Parameter x, y, z is required
400 Minimum length for parameter is x
The canonical place for additional information would be the response body.
There is precedent for using your own codes (which can be handy for log file analysis), but there is nothing wrong with putting whatever description you like in the response.