This project is read-only.

Catching Service-side Exceptions

The REST ServiceModel framework, enables developers to pass custom exceptions to the client via the RestClient class. To leverage this feature, all exceptions must be thrown through the RestFaultException class, and details provided in the ErrorDetails fault class.

VB.NET Example:
        Throw New RestFaultException(New ErrorDetails() With {
                                     .Message = "Unauthorized",
                                     .Number = 700001
                                    }, Net.HttpStatusCode.Unauthorized) 

C# Example:
        throw new RestFaultException(new ErrorDetails {
        	        Message = "Unauthorized",
        	        Number = 700001
        }, System.Net.HttpStatusCode.Unauthorized);

Exceptions of the RestFaultException class are automatically raised within the client and deserialized.

What happens to other excpetions?

Should traditional exceptions (ApplicationException, NotFoundException etc.) be raised within the service, the framework will raise a general error exception without fault details. You can still log these details service side, however no data will be passed in serialization.

Last edited Feb 28, 2013 at 1:51 PM by rasmusfoged, version 1


No comments yet.