/* (non-Javadoc)
@see com.ibm.ws.webcontainer.webapp.IWebAppDispatcherContext#sendError(int)
337717
public void sendError(int sc) throws IOException
    {
        String message;
        RequestProcessor ref = getCurrentServletReference();
        if (ref != null)
        {
            sendError(sc, MessageFormat.format(nls.getString("[{0}].reported.an.error", "[{0}] reported an error"), new Object[] { ref.getName()}));
        }
        else
        {
            sendError(
                      sc,
                      MessageFormat.format(nls.getString("[{0}].reported.an.error", "[{0}] reported an error"), new Object[] { getWebApp().getConfiguration().getDisplayName()}));
        }
    }
836453
@Override
    public void onWriteError(Exception exception, List<? extends ContentProperties> items) {
        log.error("firing onWriteError: currrently not handling: exception message=" + exception.getMessage(),
                  exception);
        for (ContentProperties props : items) {
            addError("item failed: " + props + "; exception=" + exception.getMessage());
        }
    }
349214
@Handler(channels = NetworkChannel.class)
    public void onIoError(IOError event) throws IOException {
        for (Channel channel : event.channels()) {
            if (channel instanceof TcpChannel) {
                // Error while using established network connection
                TcpChannel netConnChannel = (TcpChannel) channel;
                Optional<WebAppMsgChannel> appChannel
                    = netConnChannel.associated(WebAppMsgChannel.class);
                if (appChannel.isPresent()) {
                    // Error while using a network connection
                    appChannel.get().handleIoError(event, netConnChannel);
                    continue;
                }
                // Just in case...
                pooled.remove(netConnChannel.remoteAddress(), netConnChannel);
                continue;
            }
            // Error while trying to establish the network connection
            if (event.event() instanceof OpenTcpConnection) {
                OpenTcpConnection connEvent
                    = (OpenTcpConnection) event.event();
                Optional<Set<WebAppMsgChannel>> erroneous;
                synchronized (connecting) {
                    erroneous = Optional
                        .ofNullable(connecting.get(connEvent.address()));
                    connecting.remove(connEvent.address());
                }
                erroneous.ifPresent(set -> {
                    for (WebAppMsgChannel chann : set) {
                        chann.openError(event);
                    }
                });
            }
        }
    }
1159491
public static void sendDevTimeError( String messageKey, Throwable cause, int productionTimeErrorCode,
                                         ServletRequest request, ServletResponse response,
                                         ServletContext servletContext, Object[] messageArgs )
            throws IOException
    {
        sendDevTimeError( messageKey, messageArgs, cause, productionTimeErrorCode, request, response, servletContext );
    }
127014
@Override
    public void onRPCError(int handle, int code, String text) {
        if (handle == asyncHandle) {
            asyncHandle = 0;
            ZKUtil.fireEvent(new AsyncRPCErrorEvent(rpcName, target, code, text, handle));
            rpcName = null;
        }
    }
1138587
@Nonnull
  public ICommonsOrderedMap <IMutableEmailData, MailTransportError> send (@Nullable final Collection <IMutableEmailData> aAllMessages)
  {
    final ICommonsOrderedMap <IMutableEmailData, MailTransportError> aFailedMessages = new CommonsLinkedHashMap <> ();
    if (aAllMessages != null)
    {
      final ICommonsList <IMutableEmailData> aRemainingMessages = new CommonsArrayList <> (aAllMessages);
      MailSendException aExceptionToBeRemembered = null;

      try (final Transport aTransport = m_aSession.getTransport (m_bSMTPS ? SMTPS_PROTOCOL : SMTP_PROTOCOL))
      {
        // Add global listeners (if present)
        for (final ConnectionListener aConnectionListener : EmailGlobalSettings.getAllConnectionListeners ())
          aTransport.addConnectionListener (aConnectionListener);

        // Check if a detailed listener is present
        final ICommonsList <IEmailDataTransportListener> aEmailDataTransportListeners = EmailGlobalSettings.getAllEmailDataTransportListeners ();

        // Connect
        aTransport.connect (m_aSMTPSettings.getHostName (),
                            m_aSMTPSettings.getPort (),
                            m_aSMTPSettings.getUserName (),
                            m_aSMTPSettings.getPassword ());

        // For all messages
        for (final IMutableEmailData aEmailData : aAllMessages)
        {
          final MimeMessage aMimeMessage = new MimeMessage (m_aSession);
          try
          {
            // convert from IEmailData to MimeMessage
            MailConverter.fillMimeMessage (aMimeMessage, aEmailData, m_aSMTPSettings.getCharsetObj ());

            // Ensure a sent date is present
            if (aMimeMessage.getSentDate () == null)
              aMimeMessage.setSentDate (new Date ());

            // Get an explicitly specified message ID
            final String sMessageID = aMimeMessage.getMessageID ();

            // This creates a new message ID (besides other things)
            aMimeMessage.saveChanges ();

            if (sMessageID != null)
            {
              // Preserve explicitly specified message id...
              aMimeMessage.setHeader (HEADER_MESSAGE_ID, sMessageID);
            }
            aMimeMessage.setHeader ("X-Mailer", X_MAILER);

            if (LOGGER.isInfoEnabled ())
              LOGGER.info ("Delivering mail from " +
                              Arrays.toString (aMimeMessage.getFrom ()) +
                              " to " +
                              Arrays.toString (aMimeMessage.getAllRecipients ()) +
                              " with subject '" +
                              aMimeMessage.getSubject () +
                              "' and message ID '" +
                              aMimeMessage.getMessageID () +
                              "'");

            // Main transmit - always throws an exception
            aTransport.sendMessage (aMimeMessage, aMimeMessage.getAllRecipients ());
            throw new IllegalStateException ("Never expected to come beyong sendMessage!");
          }
          catch (final SendFailedException ex)
          {
            if (EmailGlobalSettings.isDebugSMTP ())
              LOGGER.error ("Error send mail - SendFailedException", ex);

            /*
             * Extract all addresses: the valid addresses to which the message
             * was sent, the valid address to which the message was not sent and
             * the invalid addresses
             */
            final ICommonsSet <String> aValidSent = CollectionHelper.newSetMapped (ex.getValidSentAddresses (),
                                                                                   Address::toString);
            final ICommonsSet <String> aValidUnsent = CollectionHelper.newSetMapped (ex.getValidUnsentAddresses (),
                                                                                     Address::toString);
            final ICommonsSet <String> aInvalid = CollectionHelper.newSetMapped (ex.getInvalidAddresses (),
                                                                                 Address::toString);

            final ICommonsList <MailSendDetails> aDetails = new CommonsArrayList <> ();
            Exception ex2;
            MessagingException bex = ex;
            while ((ex2 = bex.getNextException ()) != null && ex2 instanceof MessagingException)
            {
              if (ex2 instanceof SMTPAddressFailedException)
              {
                final SMTPAddressFailedException ssfe = (SMTPAddressFailedException) ex2;
                aDetails.add (new MailSendDetails (false,
                                                   ssfe.getAddress ().toString (),
                                                   ssfe.getCommand (),
                                                   ssfe.getMessage ().trim (),
                                                   ESMTPErrorCode.getFromIDOrDefault (ssfe.getReturnCode (),
                                                                                      ESMTPErrorCode.FALLBACK)));
              }
              else
                if (ex2 instanceof SMTPAddressSucceededException)
                {
                  final SMTPAddressSucceededException ssfe = (SMTPAddressSucceededException) ex2;
                  aDetails.add (new MailSendDetails (true,
                                                     ssfe.getAddress ().toString (),
                                                     ssfe.getCommand (),
                                                     ssfe.getMessage ().trim (),
                                                     ESMTPErrorCode.getFromIDOrDefault (ssfe.getReturnCode (),
                                                                                        ESMTPErrorCode.FALLBACK)));
                }

              bex = (MessagingException) ex2;
            }

            // Map addresses to details
            final ICommonsOrderedSet <MailSendDetails> aValidSentExt = new CommonsLinkedHashSet <> ();
            final ICommonsOrderedSet <MailSendDetails> aValidUnsentExt = new CommonsLinkedHashSet <> ();
            final ICommonsOrderedSet <MailSendDetails> aInvalidExt = new CommonsLinkedHashSet <> ();
            for (final MailSendDetails aFailure : aDetails)
            {
              final String sAddress = aFailure.getAddress ();
              if (aValidSent.contains (sAddress))
                aValidSentExt.add (aFailure);
              else
                if (aValidUnsent.contains (sAddress))
                  aValidUnsentExt.add (aFailure);
                else
                  aInvalidExt.add (aFailure);
            }

            final EmailDataTransportEvent aEvent = new EmailDataTransportEvent (m_aSMTPSettings,
                                                                                aEmailData,
                                                                                aMimeMessage,
                                                                                aValidSentExt,
                                                                                aValidUnsentExt,
                                                                                aInvalidExt);
            if (aValidUnsent.isEmpty () && aInvalid.isEmpty () && aValidSent.isNotEmpty ())
            {
              // Message delivered
              for (final IEmailDataTransportListener aEmailDataTransportListener : aEmailDataTransportListeners)
                aEmailDataTransportListener.messageDelivered (aEvent);

              // Remove message from list of remaining
              s_aStatsCountSuccess.increment ();
            }
            else
            {
              // Message not delivered
              for (final IEmailDataTransportListener aEmailDataTransportListener : aEmailDataTransportListeners)
                aEmailDataTransportListener.messageNotDelivered (aEvent);

              // Sending exactly this message failed
              aFailedMessages.put (aEmailData, new MailTransportError (ex, aDetails));
              s_aStatsCountFailed.increment ();
            }
            // Remove message from list of remaining as we put it in the
            // failed message list manually in case of error
            aRemainingMessages.remove (aEmailData);
          }
          catch (final MessagingException ex)
          {
            if (EmailGlobalSettings.isDebugSMTP ())
              LOGGER.error ("Error send mail - MessagingException", ex);

            final ICommonsOrderedSet <MailSendDetails> aInvalid = new CommonsLinkedHashSet <> ();
            final Consumer <IEmailAddress> aConsumer = a -> aInvalid.add (new MailSendDetails (false,
                                                                                               a.getAddress (),
                                                                                               "<generic error>",
                                                                                               ex.getMessage (),
                                                                                               ESMTPErrorCode.FALLBACK));
            aEmailData.forEachTo (aConsumer);
            aEmailData.forEachCc (aConsumer);
            aEmailData.forEachBcc (aConsumer);

            final EmailDataTransportEvent aEvent = new EmailDataTransportEvent (m_aSMTPSettings,
                                                                                aEmailData,
                                                                                aMimeMessage,
                                                                                new CommonsArrayList <> (),
                                                                                new CommonsArrayList <> (),
                                                                                aInvalid);
            // Message not delivered
            for (final IEmailDataTransportListener aEmailDataTransportListener : aEmailDataTransportListeners)
              aEmailDataTransportListener.messageNotDelivered (aEvent);

            // Sending exactly this message failed
            aFailedMessages.put (aEmailData, new MailTransportError (ex));
            // Remove message from list of remaining as we put it in the
            // failed message list manually
            aRemainingMessages.remove (aEmailData);
            s_aStatsCountFailed.increment ();
          }
        } // for all messages
      }
      catch (final AuthenticationFailedException ex)
      {
        // problem with the credentials
        aExceptionToBeRemembered = new MailSendException ("Mail server authentication failed", ex);
      }
      catch (final MessagingException ex)
      {
        if (WebExceptionHelper.isServerNotReachableConnection (ex.getCause ()))
          aExceptionToBeRemembered = new MailSendException ("Failed to connect to mail server: " +
                                                            ex.getCause ().getMessage ());
        else
          aExceptionToBeRemembered = new MailSendException ("Mail server connection failed", ex);
      }
      catch (final Exception ex)
      {
        // E.g. IllegalState from SMTPTransport ("Not connected")
        aExceptionToBeRemembered = new MailSendException ("Internal error sending mail", ex);
      }
      finally
      {
        // Was any message not sent
        if (aRemainingMessages.isNotEmpty ())
        {
          if (aExceptionToBeRemembered == null)
            aExceptionToBeRemembered = new MailSendException ("Internal error - messages are remaining but no Exception occurred!");
          for (final IMutableEmailData aRemainingMessage : aRemainingMessages)
            aFailedMessages.put (aRemainingMessage, new MailTransportError (aExceptionToBeRemembered));
        }
      }
    }
    return aFailedMessages;
  }
236005
@Override
  public final void error(String error) throws IOException {
    add(false);
    setError(newCurrentPosition, error, newCurrentExisting);
  }
479263
private void exception(Throwable e)
    {
        try
        {
            _persistent=false;
            int error_code=HttpResponse.__500_Internal_Server_Error;
            
            if (e instanceof HttpException)
            {
                error_code=((HttpException)e).getCode();
                
                if (_request==null)
                    log.warn(e.toString());
                else
                    log.warn(_request.getRequestLine()+" "+e.toString());
                log.debug(LogSupport.EXCEPTION,e);
            }
            else if (e instanceof EOFException)
            {
                LogSupport.ignore(log,e);
                return;
            }
            else
            {
                _request.setAttribute("javax.servlet.error.exception_type",e.getClass());
                _request.setAttribute("javax.servlet.error.exception",e);
                
                if (_request==null)
                    log.warn(LogSupport.EXCEPTION,e);
                else
                    log.warn(_request.getRequestLine(),e);
            }
            
            if (_response != null && !_response.isCommitted())
            {
                _response.reset();
                _response.removeField(HttpFields.__TransferEncoding);
                _response.setField(HttpFields.__Connection,HttpFields.__Close);
                _response.sendError(error_code);
            }
        }
        catch(Exception ex)
        {
            LogSupport.ignore(log,ex);
        }
    }
834205
function sendError(msg, file, line, col, err) {
        var errString = 'JSON not found';
        if (window.JSON) {
            errString = JSON.stringify(err);
        }

        if (typeof(msg) === 'object') {
            file      = msg.filename;
            line      = msg.lineno;
            col       = msg.colno;
            errString = msg.error.stack;
            msg       = msg.message;
        }

        new Image().src = pathServerAPI + 'jserrors?msg=' + encodeURIComponent(msg) + '&file=' + encodeURIComponent(file) + '&line=' + encodeURIComponent(line) + '&col=' + encodeURIComponent(col) + '&err=' + encodeURIComponent(errString);
    }
1123299
private void sendErrorJSON(HttpServletResponse response, int statusCode, String errorCode, String errorDescription) {
        final String error = "error";
        final String error_description = "error_description";
        try {
            if (errorCode != null) {
                response.setStatus(statusCode);
                response.setHeader(ClientConstants.REQ_CONTENT_TYPE_NAME,
                        "application/json;charset=UTF-8");

                JSONObject responseJSON = new JSONObject();
                responseJSON.put(error, errorCode);
                if (errorDescription != null) {
                    responseJSON.put(error_description, errorDescription);
                }
                PrintWriter pw;
                pw = response.getWriter();
                pw.write(responseJSON.toString());
                pw.flush();
            } else {
                response.sendError(statusCode);
            }
        } catch (IOException e) {
            if (tc.isDebugEnabled())
                Tr.debug(tc, "Internal error sending error message", e);
            try {
                response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            } catch (IOException ioe) {
                if (tc.isDebugEnabled())
                    Tr.debug(tc, "yet another internal error, give up", ioe);
            }
        }

    }
150817
protected void sendErrorIfSender(Throwable throwable) {
		if (!getSender().equals(ActorRef.noSender())) {
			getSender().tell(new Status.Failure(throwable), getSelf());
		}
	}
298496
@Override
    public void handleTransportError(final WebSocketSession webSocketSession, final Throwable exception) throws Exception {
        if (exception != null) {
            logger.error("[handleTransportError]", exception);
        }
    }
652372
protected void sendError( String errText, HttpServletRequest request, HttpServletResponse response )
        throws IOException
    {
        InternalUtils.sendError( "PageFlow_Custom_Error", null, request, response,
                                 new Object[]{ getDisplayName(), errText } );
    }
67615
public void setWebAppDispatcherContext(IWebAppDispatcherContext ctx) {
        // 321485
        if (TraceComponent.isAnyTracingEnabled()&&logger.isLoggable (Level.FINE)){  //306998.15
            logger.logp(Level.FINE, CLASS_NAME,"setWebAppDispatcherContext", " old context [" + this.getDispatchContext() + "] new context [" + ctx +"]");
        }
        if (WCCustomProperties.CHECK_REQUEST_OBJECT_IN_USE){
            checkRequestObjectInUse();
        }
        SRTServletRequestThreadData.getInstance().setDispatchContext(ctx);
        this._dispatchContext = (WebAppDispatcherContext) ctx;
        resetPathElements();
    }
1299099
public void doTag()
            throws JspException
    {
        // report error if there are any
        if (hasErrors()) {
            reportErrors();
            return;
        }

        PageContext pageContext = getPageContext();
        ServletContainerAdapter sa = AdapterManager.getServletContainerAdapter(pageContext.getServletContext());
        ServletRequest request = pageContext.getRequest();
        assert(sa != null);

        // check to see if we are supposed to report the error
        boolean prodMode = sa.isInProductionMode();
        if (prodMode && !_alwaysReport)
            return;

        LinkedHashMap map = (LinkedHashMap)
                InternalUtils.getBindingUpdateErrors(request);

        if (map == null)
            return;

        if (_expression != null) {
            String expr = "{" + _expression + "}";
            BindingUpdateError err = (BindingUpdateError) map.get(expr);
            if (err != null) {
                Throwable cause = err.getCause();
                String msg = (cause != null) ? cause.getMessage() : err.getMessage();
                String s = Bundle.getString("Tags_BindingUpdateError", new Object[]{_expression, msg});
                registerTagError(s, null);
                reportErrors();
            }
            return;
        }

        Iterator it = map.values().iterator();
        while (it.hasNext()) {
            BindingUpdateError err = (BindingUpdateError) it.next();
            Throwable cause = err.getCause();
            String msg = (cause != null) ? cause.getMessage() : err.getMessage();
            String s = Bundle.getString("Tags_BindingUpdateError", new Object[]{err.getExpression(), msg});
            registerTagError(s, null);
        }
        reportErrors();
    }
261039
public void sendError(HttpResponse response,int code,String msg)
    	throws IOException
    {
        Object wrapper = response.getWrapper();
        if (wrapper!=null && wrapper instanceof HttpServletResponse)
            ((HttpServletResponse)wrapper).sendError(code,msg);
        else
            super.sendError(response,code,msg);
    }
200587
function (error) {
        send(channel, new MSG.OpenResult(msg.tcpId, Protocol.toOpenResultStatus(error), null, null));
      }