/*
@ExceptionHandler(Exception.class)
public ModelAndView handleException(Exception e) {
setError(e);
String username =
SecurityContextHolder.getContext().getAuthentication().getName();
return createRedirectMav(UserController.formatUserUrl(username));
}
349900
protected static String formatUserUrl(String username) {
        String url = USERS_MAPPING + USER_MAPPING;
        url = url.replaceAll("\\{username.*\\}", username);
        return url;
    }
170011
@GetMapping(path = CasProtocolConstants.ENDPOINT_PROXY_VALIDATE_V3)
    @Override
    protected ModelAndView handle(final HttpServletRequest request, final HttpServletResponse response) throws Exception {
        return super.handleRequestInternal(request, response);
    }
478712
public static Optional<ButtonType> showException(String title, Exception e) {
        return showException(title, null, e);
    }
38334
public static String exception2String(Exception e) {
        StringWriter sw = new StringWriter();
        e.printStackTrace(new PrintWriter(sw));
        return sw.toString().trim();
    }
1034107
@PostMapping(path = SamlProtocolConstants.ENDPOINT_SAML_VALIDATE)
    @Override
    public ModelAndView handleRequestInternal(final HttpServletRequest request,
                                              final HttpServletResponse response) throws Exception {
        return super.handleRequestInternal(request, response);
    }
1280108
public static void logLoginException(
        CmsRequestContext requestContext,
        String userName,
        CmsException currentLoginException) {

        if (currentLoginException instanceof CmsAuthentificationException) {

            // the authentication of the user failed
            if (org.opencms.security.Messages.ERR_LOGIN_FAILED_DISABLED_2 == currentLoginException.getMessageContainer().getKey()) {

                // the user has been disabled
                LOG.warn(
                    Messages.get().getBundle().key(
                        Messages.LOG_LOGIN_FAILED_DISABLED_3,
                        userName,
                        requestContext.addSiteRoot(requestContext.getUri()),
                        requestContext.getRemoteAddress()));

            } else if (org.opencms.security.Messages.ERR_LOGIN_FAILED_TEMP_DISABLED_4 == currentLoginException.getMessageContainer().getKey()) {

                // the user has been disabled
                LOG.warn(
                    Messages.get().getBundle().key(
                        Messages.LOG_LOGIN_FAILED_TEMP_DISABLED_5,
                        new Object[] {
                            userName,
                            requestContext.addSiteRoot(requestContext.getUri()),
                            requestContext.getRemoteAddress(),
                            currentLoginException.getMessageContainer().getArgs()[2],
                            currentLoginException.getMessageContainer().getArgs()[3]}));

            } else if (org.opencms.security.Messages.ERR_LOGIN_FAILED_NO_USER_2 == currentLoginException.getMessageContainer().getKey()) {

                // the requested user does not exist in the database
                LOG.warn(
                    Messages.get().getBundle().key(
                        Messages.LOG_LOGIN_FAILED_NO_USER_3,
                        userName,
                        requestContext.addSiteRoot(requestContext.getUri()),
                        requestContext.getRemoteAddress()));

            } else if (org.opencms.security.Messages.ERR_LOGIN_FAILED_WITH_MESSAGE_1 == currentLoginException.getMessageContainer().getKey()) {

                // logins have been disabled by the administration
                long endTime = CmsLoginMessage.DEFAULT_TIME_END;
                if (OpenCms.getLoginManager().getLoginMessage() != null) {
                    endTime = OpenCms.getLoginManager().getLoginMessage().getTimeEnd();
                }
                LOG.info(
                    Messages.get().getBundle().key(
                        Messages.LOG_LOGIN_FAILED_WITH_MESSAGE_4,
                        new Object[] {
                            userName,
                            requestContext.addSiteRoot(requestContext.getUri()),
                            requestContext.getRemoteAddress(),
                            new Date(endTime)}));

            } else {

                // the user exists, so the password must have been wrong
                CmsMessageContainer message = Messages.get().container(
                    Messages.LOG_LOGIN_FAILED_3,
                    userName,
                    requestContext.addSiteRoot(requestContext.getUri()),
                    requestContext.getRemoteAddress());
                if (OpenCms.getDefaultUsers().isUserAdmin(userName)) {
                    // someone tried to log in as "Admin", log this in a higher channel
                    LOG.error(message.key());
                } else {
                    LOG.warn(message.key());
                }
            }
        } else {
            // the error was database related, there may be an issue with the setup
            // write the exception to the log as well
            LOG.error(
                Messages.get().getBundle().key(
                    Messages.LOG_LOGIN_FAILED_DB_REASON_3,
                    userName,
                    requestContext.addSiteRoot(requestContext.getUri()),
                    requestContext.getRemoteAddress()),
                currentLoginException);
        }
    }
25883
protected static StringBuilder handleExceptionStart(Exception e) {
        LOG.warning(ExceptionUtils.getStackTrace(e));
        StringBuilder sb = new StringBuilder();
        if (e.getMessage() != null) {
            sb.append(e.getMessage()).append(". ");
        }
        if (e.getCause() != null && e.getCause().getMessage() != null) {
            sb.append(e.getCause().getMessage()).append(". ");
        }
        return sb;
    }
416368
def process_exception(self, request, exception):
        
        if isinstance(exception, HttpRedirectRequest):
            return HttpResponseRedirect(exception.url, status=exception.status)
        else:
            return None
539564
private OAuthWebView.AuthFailure getAuthFailure(Exception e) {
        String error = getString(R.string.boxsdk_Authentication_fail);
        if (e != null) {
            // Get the proper exception
            Throwable ex = e instanceof ExecutionException ?
                    ((ExecutionException) e).getCause() :
                    e;
            if (ex instanceof BoxException) {
                BoxError boxError = ((BoxException) ex).getAsBoxError();
                if (boxError != null){
                    if (((BoxException) ex).getResponseCode() == HttpURLConnection.HTTP_FORBIDDEN || ((BoxException) ex).getResponseCode() ==  HttpURLConnection.HTTP_UNAUTHORIZED || boxError.getError().equals("unauthorized_device")   ) {
                        error += ":" + getResources().getText(R.string.boxsdk_Authentication_fail_forbidden) + "\n";
                    } else {
                        error += ":";
                    }
                    error += boxError.getErrorDescription();
                    return new OAuthWebView.AuthFailure(OAuthWebView.AuthFailure.TYPE_AUTHENTICATION_UNAUTHORIZED, error);
                }
            }
            error += ":" + ex;
        }
        return new OAuthWebView.AuthFailure(OAuthWebView.AuthFailure.TYPE_GENERIC, error);
    }
703895
public static UnitResponse createException(Throwable e) {
        return UnitResponse
                .createError(Group.CODE_EXCEPTION, e, null);
    }
982324
static SSLHandshakeException toSSLHandshakeException(Throwable e) {
        if (e instanceof SSLHandshakeException) {
            return (SSLHandshakeException) e;
        }

        return (SSLHandshakeException) new SSLHandshakeException(e.getMessage()).initCause(e);
    }
1189740
protected void redirectUser(UserRedirectRequiredException e,
			HttpServletRequest request, HttpServletResponse response)
			throws IOException {

		String redirectUri = e.getRedirectUri();
		UriComponentsBuilder builder = UriComponentsBuilder
				.fromHttpUrl(redirectUri);
		Map<String, String> requestParams = e.getRequestParams();
		for (Map.Entry<String, String> param : requestParams.entrySet()) {
			builder.queryParam(param.getKey(), param.getValue());
		}

		if (e.getStateKey() != null) {
			builder.queryParam("state", e.getStateKey());
		}

		this.redirectStrategy.sendRedirect(request, response, builder.build()
				.encode().toUriString());
	}
1349845
@ExceptionHandler({MethodArgumentNotValidException.class, ValidationException.class})
    public ResponseEntity<Response> handleValidationException() {
        return new ResponseEntity<>(
                Response.newBuilder()
                        .withMessage(translate(ExceptionCodes.VALIDATION_ERROR))
                        .withHttpStatus(HttpStatus.INTERNAL_SERVER_ERROR.toString())
                        .build(),
                HttpStatus.INTERNAL_SERVER_ERROR
        );
    }
653640
@Override
    public void handle(RequestContext context, AuthenticationException e) throws SecurityProviderException,
            IOException {
        String targetUrl = getTargetUrl();
        if (StringUtils.isNotEmpty(targetUrl)) {
            RedirectUtils.redirect(context.getRequest(), context.getResponse(), targetUrl);
        } else {
            sendError(e, context);
        }
    }
640541
@ExceptionHandler(Exception.class)
    public ModelAndView handleUnauthorizedServiceException(final HttpServletRequest req, final Exception ex) {
        return WebUtils.produceUnauthorizedErrorView();
    }
816535
private static ReflectionException handleException(String memberName, IllegalAccessException e) {
        LOGGER.error("Couldn't access member " + memberName, e);
        return new ReflectionException(e);
    }
1195732
def process_exception(self, request, exception):
        
        if isinstance(exception, (exceptions.NotAuthorized,
                                  exceptions.NotAuthenticated)):
            auth_url = settings.LOGIN_URL
            next_url = iri_to_uri(request.get_full_path())
            if next_url != auth_url:
                field_name = REDIRECT_FIELD_NAME
            else:
                field_name = None
            login_url = request.build_absolute_uri(auth_url)
            response = redirect_to_login(next_url, login_url=login_url,
                                         redirect_field_name=field_name)
            if isinstance(exception, exceptions.NotAuthorized):
                response.delete_cookie('messages')
                return shortcuts.render(request, 'not_authorized.html',
                                        status=403)

            if request.is_ajax():
                response_401 = http.HttpResponse(status=401)
                response_401['X-Horizon-Location'] = response['location']
                return response_401

            return response

        # If an internal "NotFound" error gets this far, return a real 404.
        if isinstance(exception, exceptions.NotFound):
            raise http.Http404(exception)

        if isinstance(exception, exceptions.Http302):
            # TODO(gabriel): Find a way to display an appropriate message to
            # the user *on* the login form...
            return shortcuts.redirect(exception.location)