Search in sources :

Example 1 with ResponseError

use of org.folio.rest.gobi.model.ResponseError in project mod-gobi by folio-org.

the class PostGobiOrdersHelper method handleError.

public Void handleError(Throwable throwable) {
    final javax.ws.rs.core.Response result;
    logger.error("Exception placing order", throwable.getCause());
    GobiResponse response = new GobiResponse();
    response.setError(new ResponseError());
    final Throwable t = throwable.getCause();
    if (t instanceof HttpException) {
        final int code = ((HttpException) t).getCode();
        final String message = t.getMessage();
        switch(code) {
            case 400:
                response.getError().setCode(CODE_BAD_REQUEST);
                response.getError().setMessage(HelperUtils.truncate(t.getMessage(), 500));
                result = respond400WithApplicationXml(GobiResponseWriter.getWriter().write(response));
                break;
            case 500:
                result = respond500WithTextPlain(message);
                break;
            case 401:
                result = respond401WithTextPlain(message);
                break;
            default:
                result = respond500WithTextPlain(message);
        }
    } else if (t instanceof GobiPurchaseOrderParserException) {
        response.getError().setCode(CODE_INVALID_XML);
        response.getError().setMessage(HelperUtils.truncate(t.getMessage(), 500));
        result = respond400WithApplicationXml(GobiResponseWriter.getWriter().write(response));
    } else {
        result = respond500WithTextPlain(throwable.getMessage());
    }
    asyncResultHandler.handle(Future.succeededFuture(result));
    return null;
}
Also used : GobiPurchaseOrderParserException(org.folio.gobi.exceptions.GobiPurchaseOrderParserException) ResponseError(org.folio.rest.gobi.model.ResponseError) HttpException(org.folio.gobi.exceptions.HttpException) GobiResponse(org.folio.rest.gobi.model.GobiResponse)

Aggregations

GobiPurchaseOrderParserException (org.folio.gobi.exceptions.GobiPurchaseOrderParserException)1 HttpException (org.folio.gobi.exceptions.HttpException)1 GobiResponse (org.folio.rest.gobi.model.GobiResponse)1 ResponseError (org.folio.rest.gobi.model.ResponseError)1