package com.sun.identity.saml.common;

import com.sun.identity.common.SystemConfigurationUtil;
import com.sun.identity.saml2.common.SAML2Utils;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;

public final class SAMLUtils extends SAMLUtilsCommon {
   private SAMLUtils() {
   }

   public static void sendError(HttpServletResponse response, String errorCode, String errorMsg) {
      String errorUri = SystemConfigurationUtil.getProperty("ERROR_URI");

      try {
         if (errorUri == null) {
            throw new SAMLException("No Error URI defined for flows");
         }

         if (SAML2Utils.DEBUG.messageEnabled()) {
            SAML2Utils.DEBUG.message("Redirecting to error uri: " + errorUri + " (error code " + errorCode + ", message " + errorMsg + ")");
         }

         response.sendRedirect(errorUri);
      } catch (IOException | SAMLException var7) {
         Exception e = var7;

         try {
            response.sendError(500, e.getMessage());
         } catch (IOException ioe) {
            DEBUG.error("SAMLUtils.redirectToFlowErrorUri IOException", ioe);
         }
      }
   }
}
