How to get details exception from published Web Api - error-handling

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.

Related

application logs show 500 error from call Mulesoft web service

we have a application that makes a web service call to Mule ESB and the log shows mostly 500 error code during peak hours and 200 success code during off peak hours. I am not part of the Mule team, but when I talked with them they indicate that this may not be a problem on their side, they are saying nothing is received on their ends.
Now my question is if our application logs show 500 error code, won't that indicate the request has made it to the Mule ESB but was not able to process it or still possible to get 500 error code if the request is lost somewhere due to networking / router issues or similar to that?
The question is totally generic and doesn't provide any insight on the implementation. Then his answer applies to any HTTP response from any implementation and technology, be it Mule, Java Python, etc.
The answer depends on if the server is using the 500 response correctly. If they just answer 500 because it doesn't handle errors correctly then there is nothing you can imply from that.
If 500 is used correctly it is an internal error. If the issue is that they don't receive a proper response from another backend it be argued if there is not a better response code for that like 502 or 504. In any case is that team that manages the app who should troubleshoot the error.
What you can buy sure is that the request reached the application because it responded with an HTTP response.

Possible proxy issue with WSO2 API Manager

Whenever I try to add the following endpoint, "http://ws.cdyne.com/phoneverify/phoneverify.asmx", during the Managed API setup process and press the Test button I get an error on the server. ERROR - APIProviderHostObject Error occurred while connecting to backend : "stackOverflow preventing me from showing this link", reason: Connect to ws.cdyne.com:80 timed out
When I try this exact same process on a machine outside of our proxy it works fine. I have gone into the axis2.xml file and added proxy information and even went as far as installing cntlm and setting the proxy to localhost - same error.
I can browse to the above link just fine on this machine.
My environment is Windows 10.
I assume you talk about clicking the Test button when providing Backend Endpoint in API publisher.
The way that Test button works at the moment (as far as I understand) is that it invokes HTTP HEAD method on the endpoint provided (because according to RFC 2616, "This method is often used for testing hypertext links for validity, accessibility, and recent modification.")
Then it checks response. If response is valid or 405 (method not allowed), then the URL is marked as Valid.
Thus sometimes, if backend is not properly following RFC, you might get otherwise working URLs declared as Invalid during the test because of that improper HEAD response evaluation. Obviously, this is just a check for your convenience and you can ignore the check if you know the endpoint works for the methods and resources you need it to work.
So my advice would be to try ignoring the Test and just finishing setting up and publishing the API.
P.S. I am checking it on WSO2 API Cloud but behavior is identical to downloadable API Manager.

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.

How to properly handle Axis2 generated exceptions with a REST client

I am using Axis2 v1.6.1 and Resty as a rest client. If I purposely send a malformed request that Axis2 cannot parse, for example, sending "p=0.0" where p is an Integer, then Axis2 will generate 500 HTTP Response and log an error in it's log saying something to the effect of:
[ERROR] Exception occurred while trying to invoke service method createUpdateOrganization
org.apache.axis2.AxisFault: Invalid value "0.0" for element poStart
...
This is great but I need to be able to capture this exception information in order to act upon it as part of our exception management framework.
It seems to be throwing an AxisFault exception but this is before it reaches my service so I'm not sure what I need to configure in order to get this information.
Any ideas?
I found the following article:
http://www.packtpub.com/article/handler-and-phase-in-apache-axis
Which explains exactly what I need to do. The answer is to create a custom handler for the InFaultFlow phase. :) I hope this helps somebody else!

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'.