use of org.springframework.web.method.annotation.MethodArgumentTypeMismatchException in project Backend by FredBoat.
the class RestExceptionHandler method handleTypeMismatch.
// show a better message for borked path variables
@Override
protected ResponseEntity<Object> handleTypeMismatch(TypeMismatchException ex, HttpHeaders headers, HttpStatus status, WebRequest request) {
if (ex instanceof MethodArgumentTypeMismatchException) {
MethodArgumentTypeMismatchException e = (MethodArgumentTypeMismatchException) ex;
String requiredType = e.getRequiredType() != null ? e.getRequiredType().getSimpleName() : "unknown";
String message = String.format(TYPE_MISMATCH, e.getName(), requiredType, e.getValue());
return super.handleExceptionInternal(ex, buildErrorMessage(status, message, request), headers, status, request);
}
return super.handleTypeMismatch(ex, headers, status, request);
}
use of org.springframework.web.method.annotation.MethodArgumentTypeMismatchException in project leopard by tanhaichao.
the class TrynbApiImpl method parse.
@Override
public TrynbInfo parse(TrynbLogger trynbLogger, HttpServletRequest request, String uri, Exception exception) {
ErrorConfig errorConfig = trynbDao.find(uri);
if (exception instanceof MethodArgumentTypeMismatchException) {
MethodArgumentTypeMismatchException e2 = (MethodArgumentTypeMismatchException) exception;
Exception e = (Exception) e2.getCause().getCause();
if (e != null) {
exception = e;
} else {
exception = (Exception) e2.getCause();
}
}
ExceptionConfig exceptionConfig = this.find(errorConfig, exception);
TrynbInfo trynbInfo = new TrynbInfo();
String message;
if (exceptionConfig == null || StringUtils.isEmpty(exceptionConfig.getMessage())) {
message = parseMessage(trynbInfo, exception);
} else {
message = exceptionConfig.getMessage();
trynbInfo.setTrynbMessage(true);
}
String statusCode = this.parseStatusCode(trynbLogger, exceptionConfig, request, uri, exception);
trynbInfo.setPage(errorConfig.getPage());
trynbInfo.setMessage(message);
trynbInfo.setException(exception);
trynbInfo.setStatusCode(statusCode);
return trynbInfo;
}
Aggregations