Difference between revisions of "GxRest/GxJRS/Responses"

From Gcube Wiki
Jump to: navigation, search
(What are Code Exceptions)
Line 1: Line 1:
 
=== What are Code Exceptions ===
 
=== What are Code Exceptions ===
Code Exceptions model an approach to simplify and uniform the handling of exceptions (in the Java sense) within a RESTful or REST-like services. Instead of creating separate classes for each exception type, the idea behind CodeException is to use a single, system-wide exception class. And make it extend WebApplicationException that in turn extends RuntimeException.  
+
Code Exceptions model an approach to simplify and uniform the handling of exceptions (in the Java sense) within a RESTful or REST-like services. Instead of creating separate classes for each exception type, the idea behind CodeException is to use a single, system-wide exception class. And make it extend <code lang="Java">WebApplicationException</code> (from <code lang="Java">javax.ws.rs</code>) that in turn extends <code lang="Java">RuntimeException</code>.  
  
 
Major advantages of CodeException are:
 
Major advantages of CodeException are:

Revision as of 17:20, 4 January 2018

What are Code Exceptions

Code Exceptions model an approach to simplify and uniform the handling of exceptions (in the Java sense) within a RESTful or REST-like services. Instead of creating separate classes for each exception type, the idea behind CodeException is to use a single, system-wide exception class. And make it extend WebApplicationException (from javax.ws.rs) that in turn extends RuntimeException.

Major advantages of CodeException are:

  • abstract over the response returned by a REST resource method
  • provide a single (and self-documented) point where to declare error codes and messages returned by the webapp
  • reduce the class count in a project (not to mention in a system)
  • simplify the method declaration (RuntimeExceptions do not need to be declared)
  • simplify the client code that manages only the error codes it is capable to handle
  • remove the need to declare exceptions that sometimes aren’t going to be handled anyway.