code: public static Optional<ModelAndView> hasDelegationRequestFailed(final HttpServletRequest request, final int status) {
          val params = request.getParameterMap();
          if (Stream.of("error", "error_code", "error_description", "error_message").anyMatch(params::containsKey)) {
              val model = new HashMap<String, Object>();
              if (params.containsKey("error_code")) {
                  model.put("code", StringEscapeUtils.escapeHtml4(request.getParameter("error_code")));
              } else {
                  model.put("code", status);
              }
              model.put("error", StringEscapeUtils.escapeHtml4(request.getParameter("error")));
              model.put("reason", StringEscapeUtils.escapeHtml4(request.getParameter("error_reason")));
              if (params.containsKey("error_description")) {
                  model.put("description", StringEscapeUtils.escapeHtml4(request.getParameter("error_description")));
              } else if (params.containsKey("error_message")) {
                  model.put("description", StringEscapeUtils.escapeHtml4(request.getParameter("error_message")));
              }
              model.put(CasProtocolConstants.PARAMETER_SERVICE, request.getAttribute(CasProtocolConstants.PARAMETER_SERVICE));
              model.put("client", StringEscapeUtils.escapeHtml4(request.getParameter("client_name")));
              LOGGER.debug("Delegation request has failed. Details are [{}]", model);
              return Optional.of(new ModelAndView("casPac4jStopWebflow", model));
          }
          return Optional.empty();
      }
docs: Determine if request has errors.
  
  @param request the request
  @param status  the status
  @return the optional model and view, if request is an error.