Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Pass back a deeper cause when exceptions happen
iay committed May 12, 2018
1 parent df210b7 commit ac3623f
Showing 2 changed files with 22 additions and 4 deletions.
16 changes: 16 additions & 0 deletions src/main/java/uk/org/iay/incommon/validator/api/ApiException.java
@@ -46,6 +46,19 @@ public ApiException(final HttpStatus stat, final String msg) {
when = DateTime.now();
}

/**
* Constructor.
*
* @param stat HTTP status
* @param msg message
* @param cause the {@link Throwable} that caused this exception
*/
public ApiException(final HttpStatus stat, final String msg, final Throwable cause) {
super(msg, cause);
status = stat;
when = DateTime.now();
}

/**
* Returns the wrapped {@link HttpStatus} value.
*
@@ -68,6 +81,9 @@ public Map<String, Object> toMap() {
m.put("message", getMessage());
m.put("exception", getClass().getName());
m.put("timestamp", when);
if (getCause() != null) {
m.put("cause", getCause().toString());
}
return m;
}
}
@@ -133,8 +133,9 @@ public ResponseEntity<List<Status>> validate(
final Document doc = parserPool.parse(new StringReader(metadata));
item = new DOMElementItem(doc);
} catch (final XMLParserException ex) {
LOG.info("XLMParserException: {}", ex);
throw new ApiException(HttpStatus.BAD_REQUEST, "XMLParserException: " + ex.getMessage());
LOG.info("XLMParserException: {}", ex.getMessage());
throw new ApiException(HttpStatus.BAD_REQUEST,
"XMLParserException: " + ex.getMessage(), ex.getCause());
}

// Form the item collection.
@@ -146,8 +147,9 @@ public ResponseEntity<List<Status>> validate(
try {
pipeline.execute(items);
} catch (final PipelineProcessingException ex) {
LOG.info("Pipeline failed: {}", ex);
throw new ApiException(HttpStatus.INTERNAL_SERVER_ERROR, "Pipeline failed: " + ex.getMessage());
LOG.info("Pipeline failed: {}", ex.getMessage());
throw new ApiException(HttpStatus.INTERNAL_SERVER_ERROR,
"Pipeline failed: " + ex.getMessage(), ex.getCause());
}

// Build the response from any resulting statuses

0 comments on commit ac3623f

Please sign in to comment.