http-status-codes

Does java.net.HttpUrlConnection always throw IOException if there is an error status return by Server?

扶醉桌前 提交于 2019-12-04 06:02:08
问题 I am using java.net.HttpUrlConnection to make Http request to my Server. I realized that if the Server return an error status (400 for example). HttpUrlConnection will throw an IOException corresponding to the error status. My question is: Does HttpUrlConnection always throw an IOException if the server return an error status (4xx, 5xx)? I take a look at HttpUrlConnection API description but I couldn't answer my question. Updated: Please see my test: public static void main(String[] args) {

Auth failing - 999- HTTP status code is not handled or not allowed

懵懂的女人 提交于 2019-12-04 05:57:28
问题 I using scrapy, and I would like to get Ignoring response URL.I just see in the output console this: DEBUG: Ignoring response <999 https://www.mywebsite.com>: HTTP status code is not handled or not allowed. 回答1: According to the documentation here you can add a list of HTTP status codes which should be handled by your spider even if they are not allowed by default. In your case you have to add following line to your spider definition: handle_httpstatus_list = [999] This will cause the spider

How to globally handle HTTP errors in Grails (status codes 4xx/5xx)?

不问归期 提交于 2019-12-04 05:45:08
Is there a way in Grails to catch all the possible HTTP errors before they're being sent to the client browser, as to be able to handle the content being sent to the client? I mean all 4xx and 5xx HTTP status codes , not only the 403, 404 and 500 like other have suggested. What I'd like to do is to catch all HTTP errors in the first place, without having to specify them all one by one, then in a second step I would filter (e.g. in an error controller) specific error codes that I would like to handle (e.g. 400), but at least the ones that I would not specify would render to a generic error

Catching a specific WebException (550)

别来无恙 提交于 2019-12-04 05:09:59
Let's say I create and execute a System.Net.FtpWebRequest . I can use catch (WebException ex) {} to catch any web-related exception thrown by this request. But what if I have some logic that I only want to execute when the exception is thrown due to (550) file not found ? What's the best way to do this? I could copy the exception message and test for equality: const string fileNotFoundExceptionMessage = "The remote server returned an error: (550) File unavailable (e.g., file not found, no access)."; if (ex.Message == fileNotFoundExceptionMessage) { But theoretically it seems like this message

Conditionally setting the HTTP status without directly manipulating the HttpServletResponse

こ雲淡風輕ζ 提交于 2019-12-04 04:39:39
How can I conveniently conditionally set the HTTP status code in an Spring MVC request handler? I have a request handler that responds to POST requests, for creation of a new resource. If the request is valid I want it to redirect to the URI of the new resource, returning a 201 (Created) HTTP status code. If the request is invalid I want it to give the user a chance to correct the error in the submitted form, and should not give a status code of 201. @RequestMapping(value = { "/myURI/" }, method = RequestMethod.POST) public String processNewThingForm( @ModelAttribute(value = "name") final

REST status code 204 on paginated result

℡╲_俬逩灬. 提交于 2019-12-04 04:29:46
问题 I am designing a REST like API for paginated data retrieval of a YUI-based client. The REST URL looks like this for a GET request: /app/catalog/data?startIndex=<int>&results=<int>&sort=<sting>&dir=<string> All parameters are optional, i.e. if no parameters are given, all data from DB will be dumped. Now say that there are only 1000 records in the database. Following reqeust is made: /app/catalog/data?startIndex=1100&results=25 What status code should I return if the paginated result from the

How to send http-status using JBuilder Gem

人走茶凉 提交于 2019-12-04 04:01:46
Am using Rails 3.0.19 and JBuilder Gem 2.0.6 to render JSON responses. JBuilder: https://github.com/rails/jbuilder Following is the code am using to send error-messages for a specific API. render :json, :template=>"/api/shared/errors.json.jbuilder", :status=> :bad_request For some reason, the client receives 200-ok status. While, I have expected 400 (bad_request). Any help, please? Here is my code in detail: def render_json_error_messages #render :template=> "/api/shared/errors.json.jbuilder", :status=> :bad_request, :formats => [:json] respond_to do |format| format.json { render :template=> "

HTTP: error during reply after 200 OK status code

微笑、不失礼 提交于 2019-12-04 02:51:45
As an HTTP 1.1 server, I reply to a GET request with 200 OK status code, then start sending the data to the client. During this send, an error occurs, and I cannot finish. I cannot send a new status code as a final status code has already been sent. How should I behave to let the client know an error occurred and I cannot continue with this HTTP request? I can think of only one solution: close the socket, but it's not perfect: it breaks the keep-alive feature, and no clear explanation of the error is given to the client. The HTTP standard seems to suppose that the server already knows exactly

Django REST Framework ValidationError always returns 400

吃可爱长大的小学妹 提交于 2019-12-04 02:36:42
问题 I am trying to force ValidationError to return a different status code than 400. This is what I did: class MyValidationError(ValidationError): status_code = HTTP_403_FORBIDDEN and then in a serializer: def validate_field(self, value): raise MyValidationError Why do I get 400 here instead of 403? An interesting thing is that if I use PermissionDenied with a custom status code (I tried 204) instead of ValidationError , it works as expected. 回答1: The Django RestFramework serializer validates all

HTTP status for “email not verified”

给你一囗甜甜゛ 提交于 2019-12-04 00:38:00
I have seen the list of all HTTP status codes. However to me it looks like there is no code for "email not verified" (used for authentication/authorization). Did you ever had the same "problem"? What HTTP status code did you use? I guess it should be a code starting with a 4 as it's a "client error". The 4xx class of status code is intended for situations in which the client seems to have erred: 6.5. Client Error 4xx The 4xx (Client Error) class of status code indicates that the client seems to have erred. Except when responding to a HEAD request, the server SHOULD send a representation