locked
Custom 400 error messages being overridden RRS feed

  • Question

  • User995377779 posted

    We are working on a hybrid mobile application for both iOS and android (with the help of Cordova framework). We are connecting to remote REST web service for the data to be displayed in the application.

    Our server is running on IIS 7.5. In our application, client communicates to the server using http post requests. We have our own customized error messages to be displayed in client side with 400 error code set in the response. The 400 error messages will be different based on different client request and that's purely based on the business functionality. In IIS 6, our application worked fine. Whatever error messages server gives 400, it was being passed on to client side successfully with "application/json" as content type.

    But after upgrading to IIS 7.5, the customized 400 error messages are failing to reach client side. In the client side, we are getting "400 bad request". And the content type is being set to "text/html" instead of "application/json".

    Can IIS override our 400 custom error messages? Is there something to do from IIS side configuration? We have been facing this issue for more than 2 weeks and we have no clue till now.

    If someone has ever faced this issue before, please help us out from this.

    Saturday, May 31, 2014 9:26 AM

Answers

  • User-2064283741 posted
    That is fine iis is returning that page rather than the http sys. The server headers are different.
    try walkthrough as here
    http://stackoverflow.com/questions/12908764/iis-7-5-sending-http-status-code-422-with-custom-errors-on
    • Marked as answer by Anonymous Tuesday, September 28, 2021 12:00 AM
    Tuesday, June 3, 2014 10:11 PM

All replies

  • User-1731511703 posted

    You will note in the following two links:

    You cannot customize the following HTTP errors: 400, 403.9, 411, 414, 500, 500.11, 500.14, 500.15, 501, 503, and 505.

    http://technet.microsoft.com/en-us/library/cc753103%28v=ws.10%29.aspx

    http://technet.microsoft.com/en-us/library/cc731570%28v=ws.10%29.aspx

    However, you should be able to get around that by setting this in your web.config:

        <system.webServer>
          <httpErrors errorMode="Detailed"/>
        </system.webServer>

    AND set the body of the response. 

    This can be a security risk so use it with caution.  Here's a post you can reference with the above information:

    http://stackoverflow.com/questions/8900001/iis-overwriting-http-response-text-when-http-response-status-set-as-400

    Saturday, May 31, 2014 12:59 PM
  • User-1475386077 posted

    Hello,

    Open your IIS > click web site > Error Pages > here under "Alerts" section click on "Edit Features Settings..." it will show following three option : 

    1] Custom error pages

    2] Detail errors

    3] Detailed errors for local requests and custom error pages for remote requestes.

    select 2nd option Detail errors click Ok.

    This it will show your custom 404 error pages instead any error message,

    Can you try this and let me know if it work for you ?

    Monday, June 2, 2014 6:20 AM
  • User995377779 posted

    Thanks Rick !! I tried setting the error code to 422. Still I the customized error message is not reaching client side. We are getting below error on client side:

    422 The custom error module does not recognize this error

    Any idea why this might be happenning?

    Monday, June 2, 2014 9:29 AM
  • User995377779 posted

    @StormInternet: Thanks. But, we actuaaly don't want any error page to be set here. In stead of that we want the customzed json message to reach the client side. And we are using 400 error code (it's not 404). 

    Hope I am clear in my ideas.

    Monday, June 2, 2014 9:33 AM
  • User-2064283741 posted

    Firstly is IIS returning this error or the http.sys?
    Tuesday, June 3, 2014 5:20 AM
  • User-2064283741 posted
    If http.sys is returning it probably not much you can do maybe you can tweak the http.sys registry settings to allow it though to IIS.
    if IIS is handling this does pass through make any difference.
    Tuesday, June 3, 2014 5:24 AM
  • User995377779 posted

    Do you mean I should look into httperr.logs? In that logs I can see only  Timer_ConnectionIdle

    Please find the request headers
    Connection: keep-alive
    Content-Length: 165
    Cache-Control: no-cache
    X-Requested-By: df35e81ea3184a51de92821ff6d2b923d21fba6d103990b8b38ab1671cc405306fba7f74c1ba85e9968a37d5f4b8c4dd26b56acdfb2d023dc983fa6c6bb36188
    User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.114 Safari/537.36
    Content-Type: application/json; charset=UTF-8
    Accept: application/json, text/javascript, */*; q=0.01
    X-Requested-With: XMLHttpRequest
    Accept-Encoding: gzip,deflate
    Accept-Language: en-US,en;q=0.8

    Response headers

    HTTP/1.1 400 Bad Request
    Content-Type: text/html
    Server: Microsoft-IIS/7.5
    X-Requested-By: df35e81ea3184a51de92821ff6d2b923d21fba6d103990b8b38ab1671cc405306fba7f74c1ba85e9968a37d5f4b8c4dd26b56acdfb2d023dc983fa6c6bb36188
    X-Powered-By: Servlet/2.5 JSP/2.1
    Date: Mon, 02 Jun 2014 12:24:10 GMT
    Content-Length: 11

    Bad Request

    We want content-type to be application/json for 400 .

     

     

     

    Tuesday, June 3, 2014 10:12 AM
  • User-2064283741 posted
    That is fine iis is returning that page rather than the http sys. The server headers are different.
    try walkthrough as here
    http://stackoverflow.com/questions/12908764/iis-7-5-sending-http-status-code-422-with-custom-errors-on
    • Marked as answer by Anonymous Tuesday, September 28, 2021 12:00 AM
    Tuesday, June 3, 2014 10:11 PM