当前位置: 首页>>代码示例>>Java>>正文


Java ProblemBuilder类代码示例

本文整理汇总了Java中org.zalando.problem.ProblemBuilder的典型用法代码示例。如果您正苦于以下问题:Java ProblemBuilder类的具体用法?Java ProblemBuilder怎么用?Java ProblemBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ProblemBuilder类属于org.zalando.problem包,在下文中一共展示了ProblemBuilder类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: process

import org.zalando.problem.ProblemBuilder; //导入依赖的package包/类
/**
 * Post-process Problem payload to add the message key for front-end if needed
 */
@Override
public ResponseEntity<Problem> process(@Nullable ResponseEntity<Problem> entity, NativeWebRequest request) {
    if (entity == null || entity.getBody() == null) {
        return entity;
    }
    Problem problem = entity.getBody();
    if (!(problem instanceof ConstraintViolationProblem || problem instanceof DefaultProblem)) {
        return entity;
    }
    ProblemBuilder builder = Problem.builder()
        .withType(Problem.DEFAULT_TYPE.equals(problem.getType()) ? ErrorConstants.DEFAULT_TYPE : problem.getType())
        .withStatus(problem.getStatus())
        .withTitle(problem.getTitle())
        .with("path", request.getNativeRequest(HttpServletRequest.class).getRequestURI());

    if (problem instanceof ConstraintViolationProblem) {
        builder
            .with("violations", ((ConstraintViolationProblem) problem).getViolations())
            .with("message", ErrorConstants.ERR_VALIDATION);
        return new ResponseEntity<>(builder.build(), entity.getHeaders(), entity.getStatusCode());
    } else {
        builder
            .withCause(((DefaultProblem) problem).getCause())
            .withDetail(problem.getDetail())
            .withInstance(problem.getInstance());
        problem.getParameters().forEach(builder::with);
        if (!problem.getParameters().containsKey("message") && problem.getStatus() != null) {
            builder.with("message", "error.http." + problem.getStatus().getStatusCode());
        }
        return new ResponseEntity<>(builder.build(), entity.getHeaders(), entity.getStatusCode());
    }
}
 
开发者ID:torgcrm,项目名称:TorgCRM-Server,代码行数:36,代码来源:ExceptionTranslator.java

示例2: prepare

import org.zalando.problem.ProblemBuilder; //导入依赖的package包/类
default ProblemBuilder prepare(final Throwable throwable, final StatusType status, final URI type) {
    return Problem.builder()
            .withType(type)
            .withTitle(status.getReasonPhrase())
            .withStatus(status)
            .withDetail(throwable.getMessage())
            .withCause(Optional.ofNullable(throwable.getCause())
                .filter(cause -> isCausalChainsEnabled())
                .map(this::toProblem)
                .orElse(null));
}
 
开发者ID:zalando,项目名称:problem-spring-web,代码行数:12,代码来源:AdviceTrait.java


注:本文中的org.zalando.problem.ProblemBuilder类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。