DataONEorg / bookkeeper

Bookkeeper keeps track of DataONE product subscriptions and quotas for researchers using the extended services.
Other
1 stars 2 forks source link

Fix nested exception handling #56

Closed gothub closed 4 years ago

gothub commented 4 years ago

In QuotasResource.listQuotas() and UsagesResource.listUsages(), errors are manually thrown within a containing try {} blocks, which are getting caught by the containing block, thereby causing the wrong exception type to be returned, for example:

try {
   if (x) {
       throw WebApplicationException("x error", Response.Status.FORBIDDEN)
  } 
} catch (Exception e) {
   throw ("y error", Response.Status.INTERNAL_SERVER_ERROR)
}

So, if x is true, 'Response.Status.FORBIDDEN' should be returned, but instead 'Response.Status.INTERNAL_SERVER_ERROR' gets returned.

Maybe the easiest way to fix this is to catch 'WebApplicationException' in the containing block and just re-throw it, or perhaps instead of catching 'Exception' in the outer block, catching expected errors.

Suggestions?

gothub commented 4 years ago

Fixed in commit c02715719410822587fbd6e2a51b35a27b9c4cfa