Search in sources :

Example 1 with ExceptionInfo

use of com.qcadoo.view.api.exception.ExceptionInfo in project qcadoo by qcadoo.

the class DefaultExceptionResolver method doResolveException.

@Override
protected ModelAndView doResolveException(final HttpServletRequest request, final HttpServletResponse response, final Object handler, final Exception exception) {
    ModelAndView mv = super.doResolveException(request, response, handler, exception);
    if (mv == null) {
        return mv;
    }
    String codeStr = mv.getViewName();
    int code = Integer.parseInt(codeStr);
    CustomTranslationMessage customExceptionMessage = getCustomExceptionMessage(exception);
    if (LOG.isDebugEnabled()) {
        LOG.debug("Adding exception message to view: " + customExceptionMessage);
    }
    String customExceptionMessageHeader = null;
    String customExceptionMessageExplanation = null;
    @SuppressWarnings("rawtypes") ExceptionInfoResolver exceptionInfoResolver = classResolversMap.get(exception.getClass());
    if (exceptionInfoResolver != null) {
        @SuppressWarnings("unchecked") ExceptionInfo info = exceptionInfoResolver.getExceptionInfo(exception);
        customExceptionMessageHeader = translationService.translate(info.getMessageHeader(), LocaleContextHolder.getLocale());
        customExceptionMessageExplanation = translationService.translate(info.getMessageExplanation(), LocaleContextHolder.getLocale(), info.getMessageExplanationArgs());
    } else if (customExceptionMessage != null) {
        customExceptionMessageHeader = translationService.translate("qcadooView.errorPage.error." + customExceptionMessage.getMessage() + ".header", LocaleContextHolder.getLocale());
        if (customExceptionMessage.getEntityIdentifier() == null) {
            if ("uploadException.maxSizeExceeded".equals(customExceptionMessage.getMessage())) {
                customExceptionMessageExplanation = translationService.translate("qcadooView.errorPage.error." + customExceptionMessage.getMessage() + ".explanation", LocaleContextHolder.getLocale(), "" + maxUploadSize / 1000000);
            } else {
                customExceptionMessageExplanation = translationService.translate("qcadooView.errorPage.error." + customExceptionMessage.getMessage() + ".explanation", LocaleContextHolder.getLocale());
            }
        } else {
            customExceptionMessageExplanation = translationService.translate("qcadooView.errorPage.error." + customExceptionMessage.getMessage() + ".explanation", LocaleContextHolder.getLocale(), customExceptionMessage.getEntityIdentifier());
        }
        Throwable rootException = getRootException(exception);
        if (rootException instanceof CopyException) {
            String copyExplanation = getAdditionalMessageForCopyException((CopyException) rootException, LocaleContextHolder.getLocale());
            if (copyExplanation != null) {
                customExceptionMessageExplanation = copyExplanation;
            }
        }
    }
    return errorController.getAccessDeniedPageView(code, exception, customExceptionMessageHeader, customExceptionMessageExplanation, LocaleContextHolder.getLocale());
}
Also used : CopyException(com.qcadoo.model.api.CopyException) ExceptionInfoResolver(com.qcadoo.view.api.exception.ExceptionInfoResolver) ModelAndView(org.springframework.web.servlet.ModelAndView) ExceptionInfo(com.qcadoo.view.api.exception.ExceptionInfo)

Aggregations

CopyException (com.qcadoo.model.api.CopyException)1 ExceptionInfo (com.qcadoo.view.api.exception.ExceptionInfo)1 ExceptionInfoResolver (com.qcadoo.view.api.exception.ExceptionInfoResolver)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1