Esempio n. 1
0
 default void end(RoutingContext context, HttpResponseStatus statusCode) {
   context
       .response()
       .setStatusCode(statusCode.code())
       .setStatusMessage(statusCode.reasonPhrase())
       .end();
 }
Esempio n. 2
0
  default <T extends Throwable> void error(
      RoutingContext context, HttpResponseStatus code, String message, T object) {
    HttpServerResponse response = context.response().setStatusCode(code.code());
    response.putHeader("X-API-Gateway-Error", "true");

    if (message == null) {
      response.setStatusMessage(code.reasonPhrase());
    } else {
      response.setStatusMessage(message);
    }

    if (object != null) {
      JsonObject errorResponse =
          new JsonObject()
              .put("errorType", object.getClass().getSimpleName())
              .put("message", object.getMessage());

      response
          .setChunked(true)
          .putHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
          .end(errorResponse.toString(), "UTF-8");
    } else {
      response.end();
    }
  }