use of com.helger.smpclient.exception.SMPClientBadRequestException in project peppol-commons by phax.
the class AbstractGenericSMPClient method getConvertedException.
/**
* Convert the passed generic HTTP exception into a more specific exception.
*
* @param ex
* The generic exception. May not be <code>null</code>.
* @return A new SMP specific exception, using the passed exception as the
* cause.
*/
@Nonnull
public static SMPClientException getConvertedException(@Nonnull final Exception ex) {
if (LOGGER.isDebugEnabled())
LOGGER.debug("Converting exception of class '" + ex.getClass().getName() + "' to an SMP expception");
if (ex instanceof SMPClientException)
return (SMPClientException) ex;
if (ex instanceof HttpResponseException) {
final HttpResponseException hex = (HttpResponseException) ex;
final int nHttpStatus = hex.getStatusCode();
switch(nHttpStatus) {
case HttpStatus.SC_BAD_REQUEST:
return new SMPClientBadRequestException(hex);
case HttpStatus.SC_FORBIDDEN:
return new SMPClientUnauthorizedException(hex);
case HttpStatus.SC_NOT_FOUND:
return new SMPClientNotFoundException(hex);
default:
return new SMPClientException("Error thrown with HTTP status code " + nHttpStatus, hex);
}
}
// Special case
if (ex instanceof UnknownHostException)
return new SMPClientNotFoundException((UnknownHostException) ex);
if (ex instanceof ConnectException)
return new SMPClientNotFoundException((ConnectException) ex);
// For new SMPClientBadResponseException
if (ex instanceof ClientProtocolException && ex.getCause() instanceof SMPClientException)
return (SMPClientException) ex.getCause();
// Generic version
return new SMPClientException("Unknown error thrown by SMP server (" + ex.getMessage() + ")", ex);
}
Aggregations