Search in sources :

Example 1 with MethodArgumentTypeMismatchException

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);
}
Also used : MethodArgumentTypeMismatchException(org.springframework.web.method.annotation.MethodArgumentTypeMismatchException)

Example 2 with MethodArgumentTypeMismatchException

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;
}
Also used : MethodArgumentTypeMismatchException(org.springframework.web.method.annotation.MethodArgumentTypeMismatchException) TrynbInfo(io.leopard.mvc.trynb.model.TrynbInfo) ErrorConfig(io.leopard.mvc.trynb.model.ErrorConfig) ExceptionConfig(io.leopard.mvc.trynb.model.ExceptionConfig) ApiException(io.leopard.core.exception.ApiException) MethodArgumentTypeMismatchException(org.springframework.web.method.annotation.MethodArgumentTypeMismatchException)

Aggregations

MethodArgumentTypeMismatchException (org.springframework.web.method.annotation.MethodArgumentTypeMismatchException)2 ApiException (io.leopard.core.exception.ApiException)1 ErrorConfig (io.leopard.mvc.trynb.model.ErrorConfig)1 ExceptionConfig (io.leopard.mvc.trynb.model.ExceptionConfig)1 TrynbInfo (io.leopard.mvc.trynb.model.TrynbInfo)1