Customize Error Pages for HTTP error codes? - hana

How can I have custom error pages for HTTP errors like 401, 403, 404, ... in HANA (version 1.00.122.08)?

In case this question refers to the XSC (classic) version of the web application server, the answer is: there is no option to customize the error messages.
On option to deal with this is to handle all requests through an inverse proxy/load balancer and use its custom error messages.

Related

how to handle http connector response code

Currently in mule, I have a flow process that makes an http connection to elasticsearch. We are using the scroll api and all connections are fine. I am trying to create a flow to handle the 404 status code which would be returned in the event that the scroll_id has expired on a request. At the moment, I added code 404 to the advanced settings for "Failure Status Code Validator" section on the http connector. What I want to accomplish is that when 404 is returned from this particular http call (which we know is due to the scroll_id expiry), we make another http call to another gateway. So when 404, make another http call to a separate link.
Thanks in advance. I am still learning the xml code, but if you have an anypoint studio experience in the GUI that would be extremely helpful.
I accomplished this by setting a success status code validator under the Advanced tab of the http-connector.
Before setting this value, when getting a 404, the mulesoft would raise its default exception for error code 4xx. At the moment, I still can't figure out how to override that or set something additional, and that could be due to this particular project I am taking over. However, in the success code validator section, I set the values to 200,404 which is saying that a status code of 200 and 404 can pass to the next component in the flow. By default, if you don't set 404, again mulesoft will throw its default built in error message for status code 404. So since I am telling mulesoft to treat this as okay, I can pass to the next component in my project. At the next flow immediately after the outbound http call to an external rest service, I have a choice-component in place that is evaluating what the status code of the http call is. To do this, you can use this: #[message.inboundProperties.'http.status' == '404'] which is saying, use this particular flow path if the status code is 404, else use the default path.

How to show the internal server errors to the user?

I am working in an API . I want to throw detailed error messages to the user. Now i am in a situation to decide what kind of error code should be sent or how to explain user if any error occurs in the application internally. For example if database connection fails , what kind of http status code i want to send to the user ?
Can anyone help ?
An HTTP status code generally refers to the status of the HTTP request itself, not the status of the application handling the request. Therefore, most server-side errors are covered by 500 Internal Server Error. Any additional info about the error should be described in the response body. For APIs, the response body will often be JSON or XML, so you can use those formats for your errors. Something like this:
HTTP/1.1 500 Internal Server Error
[headers]
{"status":"error", "message":"The request failed due to database connectivity."}
There are, however, two cases I can think of when you might want another status code. If the user has requested an API method that is not implemented, you might want a 501 Not Implemented, and when there is a temporary service outage, you can use 503 Service Unavailable.
More info about server-side status codes here.

How to get details exception from published Web Api

Is there any way to get detail exception & Stack trace from deployed Web Api?
Even if I deployed in Debug mode, do I get detail error traces?
I got bellow message from server API
"message": "Processing of the HTTP request resulted in an exception.
Please see the HTTP response returned by the 'Response' property of
this exception for details."
This happened only in server, same code running perfectly in local machine.
Did you check the content-type for the request that you are performing?
Sometimes this error comes because you don't specify this value, e.g. "application/json" in the headers of the request.
If your scenario is to have a central place to log any exceptions that happen when requests are being processed, then I would suggest to take a look at 5.1 version of Web API (released couple of days back), specifically the Global Error Handling feature.
http://www.asp.net/web-api/overview/releases/whats-new-in-aspnet-web-api-21#global-error
If you go to the above page,you should notice ExceptionLoggerContext which gives you details of the exception.
About Web API versions 5.0 and before:
In these versions there was no really a central place for catching exceptions. ExceptionFilterAttributes caught exceptions for only certain areas of Web API.

Display custom error message in wcf invalid method in route table

I have implemented a RESTful API using wcf and I use System.Web.Routing.RouteTable.Routes.Add(...) to map the methods to URLs. If a user types an invalid url (i.e. a url that does not map to a method), say myapiurl/geeet/ instead of myapiurl/get/ then currently a standard error message like "Method not allowed" is displayed.
How do I customize this error message?
I have tried Application_Error in Global.asax, but it does not catch the exception.
I have also implemented a IErrorHandler, IServiceBehavior, but it also does not catch this error.
Neither does the WebHttpBehavior I have implemented.
The "Method not allowed" (HTTP status code 405) message means the server is receiving a request from a client using an HTTP method (GET, POST, PUT, etc.) that is not allowed by the server (IIS). For example the client is submitting a PUT request and IIS is not configured to accept PUT. I think by default, IIS only supports GET and POST.
A bad URI, as you describe in your question, generally results in a HTTP status code of 404 resource not found. Sound like your IIS configuration may be causing your issue since you can't trap the exception at either the ASP.NET or WCF layer.

What are the 404;1, 404;2 etc HTTP error codes for?

In IIS I can configure my custom error pages.
For each HTTP Error code I can say where to go. Several codes have a number of "sub" codes available. For example 404 has a regular 404, 404;1, 404;2 and so on..
What are they for? When are they returned? Should I make custom pages for these errors? Can I somehow easely configure all code "families" to come to the same page?
401 - Access denied. IIS defines several different 401 errors that indicate a more specific cause of the error. These specific error codes are displayed in the browser but are not displayed in the IIS log:
401.1 - Logon failed.
401.2 - Logon failed due to server configuration.
401.3 - Unauthorized due to ACL on resource.
401.4 - Authorization failed by filter.
401.5 - Authorization failed by ISAPI/CGI application.
401.7 – Access denied by URL authorization policy on the Web server (This error code is specific to IIS 6.0.)
Here is the complete list in the MSDN documentation for IIS 5.0 and 6.0 and for IIS 7.0, 7.5 and 8.0.
If you want to show your visitors or users a nice custom message depending on these subcode, you could do it. But you needn't.
"Substatus" error codes are specific to IIS. They are for "internal" logging purposes - whatever the substatus code, it is the the parent error that gets returned to the client (404.2 gets sent back as 404)
They were implemented specifically to reduce the surface area of attack of IIS whilst still providing sysadmins with a meaningful amount of data. Therefore you actively should not send back specific substatus error messages as you will be opening your IIS installation to possible attack.
Reference
This blog article appears to explain a lot of this. Perhaps it can be of help? At the very least, it explains the meaning of the 'sub-codes'.