Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The best way of exception handling in an app with web services

I have an application which consists of SOAP and REST web services and a simple HTTP access. All of them convert incoming requests and send them to a handler. The most painful thing is exception handling. In order to return the right response, I have to wrap every method with try-catch block and create a response there.

I thought that I could create a filter which could do it. But how can the filter recognise the source of it (soap, rest frontend) so I knew that I should return a SOAP or other response?

like image 284
user219882 Avatar asked Mar 07 '12 08:03

user219882


People also ask

How do you handle exceptions in Web services?

We do this by using the Code property of the SoapException object. The Code property will be set to Client if the exception is caused by an invalid input from the client. If the exception is caused by the Web service code (for example, the database server is down), the Code property will be set to Server.

What are the 3 approaches to handling exceptions in a web application?

try catch finally 2. Use error events to deal with exceptions within the scope of an object. Page_Error Global_Error Application_Error 3. Use custom error pages to display informational messages for unhandled exceptions within the scope of a Web application.

What helps in handling exceptions in Microservices?

Spring Boot is a microservice-based framework and making a production-ready application in it takes very little time. Exception Handling in Spring Boot helps to deal with errors and exceptions present in APIs so as to deliver a robust enterprise application.


1 Answers

It depends on the WS framework you use. All I know have some sort of interceptors/aspects that you can inject and handle exceptions in one place. For instance in apache-cxf there is even a special outbound error chain where you can plug your own interceptors.

Obviously try-catch in every method is a bad idea.

like image 191
Tomasz Nurkiewicz Avatar answered Sep 19 '22 18:09

Tomasz Nurkiewicz