@Override public ActionResponse apply(HttpResponse response) { return apply(response, false); }
@Override public void propagate(HttpResponse response) { if (response.getStatus() == statusCode) { ActionResponse ar = ResponseToActionResponse.INSTANCE.apply(response); throw mapException(ar.getFault(), response.getStatus()); } }
public ActionResponse apply(HttpResponse response, String action) { try { if (response.getStatus() == 409 || response.getStatus() == 500) { ActionResponse ar = ResponseToActionResponse.INSTANCE.apply(response, true); if (ar != null) { return ar; } LOG.error("{}, {}", response.getStatus(), response.getStatusMessage()); if (action == null) { return ActionResponse.actionFailed("Instance currently is in build state", 409); } return ActionResponse.actionFailed(String.format(FAILED_MSG, action, action), 409); } if (response.getStatus() >= 400 && response.getStatus() < 409) { return ResponseToActionResponse.INSTANCE.apply(response); } return ActionResponse.actionSuccess(); } finally { HttpEntityHandler.closeQuietly(response); } }
@SuppressWarnings("unchecked") private static <T> Handle<T> handleLessThan500(Handle<T> handle) { if (handle.getResponse().getStatus() < 500) { try { ActionResponse ar = ResponseToActionResponse.INSTANCE.apply(handle.getResponse()); if (handle.getReturnType() == ActionResponse.class) { return handle.complete((T) ar); } throw mapException(ar.getFault(), handle.getResponse().getStatus()); } catch (ResponseException re) { throw re; } catch (Exception e) { LOG.error(e.getMessage(), e); } } return handle.continueHandling(); }
return (T) ResponseToActionResponse.INSTANCE.apply(response);