本文整理了Java中io.micronaut.http.HttpResponse.badRequest()
方法的一些代码示例,展示了HttpResponse.badRequest()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpResponse.badRequest()
方法的具体详情如下:
包路径:io.micronaut.http.HttpResponse
类名称:HttpResponse
方法名:badRequest
[英]Return an io.micronaut.http.HttpStatus#BAD_REQUEST response with an empty body.
[中]返回一个io。微纳特。http。HttpStatus#请求响应错误,正文为空。
代码示例来源:origin: micronaut-projects/micronaut-core
@Override
public HttpResponse handle(HttpRequest request, DuplicateRouteException exception) {
JsonError error = new JsonError(exception.getMessage());
error.link(Link.SELF, Link.of(request.getUri()));
return HttpResponse.badRequest(error);
}
}
代码示例来源:origin: micronaut-projects/micronaut-core
@Override
public HttpResponse handle(HttpRequest request, UnsatisfiedRouteException exception) {
if (LOG.isErrorEnabled()) {
LOG.error("{} (Bad Request): {}", request, exception.getMessage());
}
JsonError error = new JsonError(exception.getMessage());
error.path('/' + exception.getArgument().getName());
error.link(Link.SELF, Link.of(request.getUri()));
return HttpResponse.badRequest(error);
}
}
代码示例来源:origin: micronaut-projects/micronaut-core
@Override
public HttpResponse handle(HttpRequest request, ConversionErrorException exception) {
JsonError error = new JsonError(exception.getMessage());
error.path('/' + exception.getArgument().getName());
error.link(Link.SELF, Link.of(request.getUri()));
return HttpResponse.badRequest(error);
}
}
代码示例来源:origin: micronaut-projects/micronaut-core
@Override
public HttpResponse handle(HttpRequest request, UnsatisfiedArgumentException exception) {
JsonError error = new JsonError(exception.getMessage());
error.path('/' + exception.getArgument().getName());
error.link(Link.SELF, Link.of(request.getUri()));
return HttpResponse.badRequest(error);
}
}
代码示例来源:origin: io.micronaut/micronaut-validation
@Override
public HttpResponse<JsonError> handle(HttpRequest request, ConstraintViolationException exception) {
Set<ConstraintViolation<?>> constraintViolations = exception.getConstraintViolations();
if (constraintViolations == null || constraintViolations.isEmpty()) {
JsonError error = new JsonError(exception.getMessage() == null ? HttpStatus.BAD_REQUEST.getReason() : exception.getMessage());
error.link(Link.SELF, Link.of(request.getUri()));
return HttpResponse.badRequest(error);
} else if (constraintViolations.size() == 1) {
ConstraintViolation<?> violation = constraintViolations.iterator().next();
JsonError error = new JsonError(buildMessage(violation));
error.link(Link.SELF, Link.of(request.getUri()));
return HttpResponse.badRequest(error);
} else {
JsonError error = new JsonError(HttpStatus.BAD_REQUEST.getReason());
List<Resource> errors = new ArrayList<>();
for (ConstraintViolation<?> violation : constraintViolations) {
errors.add(new JsonError(buildMessage(violation)));
}
error.embedded("errors", errors);
error.link(Link.SELF, Link.of(request.getUri()));
return HttpResponse.badRequest(error);
}
}
代码示例来源:origin: io.micronaut/http-server
@Override
public HttpResponse handle(HttpRequest request, ConversionErrorException exception) {
JsonError error = new JsonError(exception.getMessage());
error.path('/' + exception.getArgument().getName());
error.link(Link.SELF, Link.of(request.getUri()));
return HttpResponse.badRequest(error);
}
}
代码示例来源:origin: io.micronaut/http-server
@Override
public HttpResponse handle(HttpRequest request, UnsatisfiedArgumentException exception) {
JsonError error = new JsonError(exception.getMessage());
error.path('/' + exception.getArgument().getName());
error.link(Link.SELF, Link.of(request.getUri()));
return HttpResponse.badRequest(error);
}
}
代码示例来源:origin: io.micronaut/micronaut-validation
@Override
public HttpResponse<JsonError> handle(HttpRequest request, ValidationException exception) {
Errors errors = exception.getErrors();
JsonError error = new JsonError(exception.getMessage());
FieldError fieldError = errors.getFieldError();
if (fieldError != null) {
error.path(fieldError.getField());
}
error.link(Link.SELF, Link.of(request.getUri()));
return HttpResponse.badRequest(error);
}
}
内容来源于网络,如有侵权,请联系作者删除!