/** * Ends a response with a given HTTP status code and detail message. * * @param ctx The vert.x routing context to fail. * @param status The status code to write to the response. * @param headers HTTP headers to set on the response (may be {@code null}). * @param detail The message to write to the response's body (may be {@code null}). * @throws NullPointerException if routing context is {@code null}. * @deprecated Use {@link #failWithHeaders(RoutingContext, ServiceInvocationException, Map)} instead. */ @Deprecated public static void failWithStatus( final RoutingContext ctx, final int status, final Map<CharSequence, CharSequence> headers, final String detail) { failWithHeaders(ctx, new ServiceInvocationException(status, detail), headers); }
/** * Ends a response with a given HTTP status code and detail message. * * @param ctx The vert.x routing context to fail. * @param status The status code to write to the response. * @param headers HTTP headers to set on the response (may be {@code null}). * @param detail The message to write to the response's body (may be {@code null}). * @throws NullPointerException if routing context is {@code null}. * @deprecated Use {@link #failWithHeaders(RoutingContext, ServiceInvocationException, Map)} instead. */ public static void failWithStatus( final RoutingContext ctx, final int status, final Map<CharSequence, CharSequence> headers, final String detail) { failWithHeaders(ctx, new ServiceInvocationException(status, detail), headers); }
/** * Creates an exception for a status code and detail message. * * @param statusCode The status code. * @param detailMessage The detail message. * @return The exception. * @throws NullPointerException if the response does not contain an error code. */ public static final ServiceInvocationException from(final int statusCode, final String detailMessage) { if (200 <= statusCode && statusCode < 300) { throw new IllegalArgumentException("status code " + statusCode + " does not represent an error"); } else if (400 <= statusCode && statusCode < 500) { switch(statusCode) { case HttpURLConnection.HTTP_CONFLICT: return new ResourceConflictException(detailMessage); default: return new ClientErrorException(statusCode, detailMessage); } } else if (500 <= statusCode && statusCode < 600) { return new ServerErrorException(statusCode, detailMessage); } else { return new ServiceInvocationException(statusCode, detailMessage); } }
result.completeExceptionally(new ServiceInvocationException(response.statusCode()));