Swagger UI - 响应代码

时间:2018-04-23 12:33:07

标签: spring swagger-ui swagger-2.0 swagger-editor

我对Swagger很新,我对回复的代码有点困惑。

我编写了一个代码,目的是它应该使用响应代码500删除错误消息。

如果我让我的代码运行,那么该方法会给出200 - ok状态,尽管在标题中我的错误代码是可见的。但是在Swagger中,只有当我点击"试试它"按钮...

见下图......:

enter image description here

enter image description here

这是正常行为吗?我希望只看到我的错误代码,而不是OK消息和状态......是否可能?

以下是我的代码中的简短代码段:

@GET
@Path("/pong")
@Produces(UTF8MediaType.UTF8_APPLICATION_JSON)
@ApiOperation(value = "Check whether Error handler works or nottttttttttt", response = String.class)
public String pong() throws GeneralError {
    throw new GeneralError(httpServletRequest);
}

@Override
public Response toResponse(final Throwable throwable) {
    GeneralError generalError;

    try {
        generalError = (GeneralError) throwable;
    } catch (Exception e) {
        generalError = new GeneralError(throwable);
    }

    String json = JacksonMapper.prettyPrint(generalError);

    return Response
            .status(generalError.getHttpStatus())
            .type(UTF8MediaType.UTF8_APPLICATION_JSON)
            .entity(json)
            .build();
}

提前多多感谢! :)

0 个答案:

没有答案