Spring: return @ResponseBody “ResponseEntity”
Instead of return new ResponseEntity<JSONObject>(entities, HttpStatus.OK); try return new ResponseEntity<List<JSONObject>>(entities, HttpStatus.OK);
Instead of return new ResponseEntity<JSONObject>(entities, HttpStatus.OK); try return new ResponseEntity<List<JSONObject>>(entities, HttpStatus.OK);
You may want to consider status code 429, defined in https://www.rfc-editor.org/rfc/rfc6585#section-4.
The correct response, when a server is unable to handle a request, is 503 Service Unavailable. When the condition is temporary, as it is in your case, you can set the Retry-After header to let the client know how long it should wait before trying again. However, this will not force the browser to perform …
If you use HTTP authentication as defined by RFC 7235, 401 would be correct (for missing or incorrect credentials). Howewer you have to implement WWW-Authenticate header field. Otherwise, use RFC 7231 6.5.3. 403 Forbidden. Note though that 404 is also applicable as per the above link: An origin server that wishes to “hide” the current …
To answer your questions: How to deal with unauthorized requests? The way you described it is pretty much the recommended way for a RESTful service. As far as I can see there is absolutely nothing wrong with that. What WWW-Authenticate header should 401 responses supply? In general the WWW-Authenticate header tells the client what kind …
I had this exact same problem; in order to make sure that the correct answer is not buried in the comments (as it was for me), I want to reiterate @Sprockincat’s comment: For me at least, it was indeed an issue with IIS Custom errors, and can be solved with: Response.TrySkipIisCustomErrors = true; @Sprockincat – …
This is exactly what 400 is for. Yes, it’s used for bad HTTP protocol usage, but it’s not exclusively for that purpose.
Well, I think it’s up to you which error code you’ll use. But if the actual functionality of your API depends on a third-party API, I would consider using the HTTP code 503 Service Unavailable, because your service will be unavailable until the third-party API works, no matter what HTTP code the third-party API returned. …
Or, how can I ensure error.networkResponse is non-null in onErrorResponse? My first thought would be to check if the object is null. @Override public void onErrorResponse(VolleyError error) { NetworkResponse networkResponse = error.networkResponse; if (networkResponse != null && networkResponse.statusCode == HttpStatus.SC_UNAUTHORIZED) { // HTTP Status Code: 401 Unauthorized } } Alternatively, you could also try grabbing …
I was using RestSharp which returns the server response status code in a property of type HttStatusCode and I needed to check for a 422 response myself but the of course the type doesn’t include it. Fortunately I was still able to test using the following: if(response.StatusCode == (HttpStatusCode)422) { // Do my stuff.. }