Search in sources :

Example 1 with Builder

use of org.webpieces.grpc.ErrorResponse.Builder in project webpieces by deanhiller.

the class GrpcJsonCatchAllFilter method translateError.

protected RenderContent translateError(Throwable t) {
    Builder builder = ErrorResponse.newBuilder();
    builder.setError("Server ran into a bug, please report");
    builder.setCode(500);
    byte[] content = translateJson(builder);
    KnownStatusCode status = KnownStatusCode.HTTP_500_INTERNAL_SVR_ERROR;
    return new RenderContent(content, status.getCode(), status.getReason(), MIME_TYPE);
}
Also used : Builder(org.webpieces.grpc.ErrorResponse.Builder) MessageOrBuilder(com.google.protobuf.MessageOrBuilder) RenderContent(org.webpieces.router.api.controller.actions.RenderContent) KnownStatusCode(org.webpieces.httpparser.api.dto.KnownStatusCode)

Example 2 with Builder

use of org.webpieces.grpc.ErrorResponse.Builder in project webpieces by deanhiller.

the class GrpcJsonCatchAllFilter method translate.

protected Action translate(ForbiddenException t) {
    Builder builder = ErrorResponse.newBuilder();
    builder.setError(t.getHttpCode() + " " + t.getStatusMessage() + ": " + t.getMessage());
    builder.setCode(t.getHttpCode());
    byte[] content = translateJson(builder);
    KnownStatusCode status = KnownStatusCode.HTTP_401_UNAUTHORIZED;
    return new RenderContent(content, status.getCode(), status.getReason(), MIME_TYPE);
}
Also used : Builder(org.webpieces.grpc.ErrorResponse.Builder) MessageOrBuilder(com.google.protobuf.MessageOrBuilder) RenderContent(org.webpieces.router.api.controller.actions.RenderContent) KnownStatusCode(org.webpieces.httpparser.api.dto.KnownStatusCode)

Example 3 with Builder

use of org.webpieces.grpc.ErrorResponse.Builder in project webpieces by deanhiller.

the class GrpcJsonCatchAllFilter method createNotFoundJsonResponse.

protected byte[] createNotFoundJsonResponse() {
    Builder builder = ErrorResponse.newBuilder();
    builder.setError("404 This url does not exist.  try another url");
    builder.setCode(404);
    return translateJson(builder);
}
Also used : Builder(org.webpieces.grpc.ErrorResponse.Builder) MessageOrBuilder(com.google.protobuf.MessageOrBuilder)

Example 4 with Builder

use of org.webpieces.grpc.ErrorResponse.Builder in project webpieces by deanhiller.

the class GrpcJsonCatchAllFilter method translate.

protected RenderContent translate(BadRequestException t) {
    Builder builder = ErrorResponse.newBuilder();
    builder.setError(t.getHttpCode() + " " + t.getStatusMessage() + ": " + t.getMessage());
    builder.setCode(t.getHttpCode());
    byte[] content = translateJson(builder);
    KnownStatusCode status = KnownStatusCode.HTTP_400_BADREQUEST;
    return new RenderContent(content, status.getCode(), status.getReason(), MIME_TYPE);
}
Also used : Builder(org.webpieces.grpc.ErrorResponse.Builder) MessageOrBuilder(com.google.protobuf.MessageOrBuilder) RenderContent(org.webpieces.router.api.controller.actions.RenderContent) KnownStatusCode(org.webpieces.httpparser.api.dto.KnownStatusCode)

Example 5 with Builder

use of org.webpieces.grpc.ErrorResponse.Builder in project webpieces by deanhiller.

the class GrpcJsonCatchAllFilter method createNotFound.

protected Action createNotFound() {
    Builder builder = ErrorResponse.newBuilder();
    builder.setError("404 This url does not exist.  try another url");
    builder.setCode(404);
    byte[] content = translateJson(builder);
    return new RenderContent(content, KnownStatusCode.HTTP_404_NOTFOUND.getCode(), KnownStatusCode.HTTP_404_NOTFOUND.getReason(), MIME_TYPE);
}
Also used : Builder(org.webpieces.grpc.ErrorResponse.Builder) MessageOrBuilder(com.google.protobuf.MessageOrBuilder) RenderContent(org.webpieces.router.api.controller.actions.RenderContent)

Aggregations

MessageOrBuilder (com.google.protobuf.MessageOrBuilder)6 Builder (org.webpieces.grpc.ErrorResponse.Builder)6 RenderContent (org.webpieces.router.api.controller.actions.RenderContent)5 KnownStatusCode (org.webpieces.httpparser.api.dto.KnownStatusCode)4