phax / phase4

phase4 - AS4 client and server for integration into existing systems. Specific support for Peppol and CEF eDelivery built-in.
Apache License 2.0
147 stars 48 forks source link

Give access to the HTTP error response #224

Closed ri4a closed 2 months ago

ri4a commented 6 months ago

When sending a document fails with an HTTP error, it is not currently possible to determine this and get the HTTP error. That would be very helpful, since that error message could be shown/sent to the sender in the UI/webhook. With the HTTP response code it would also be possible to determine whether a retry could work (500: yes, 400: probably not).

phax commented 2 months ago

This can be achieved with the current solution like this:

  1. remember the exception in sending:
    final Wrapper <Phase4Exception> aSendingExceptionKeeper = new Wrapper <> ();
    Phase4PeppolSender.builder ()....sendMessageAndCheckForReceipt (aSendingExceptionKeeper::set);
  2. afterwards evaluate the sending exception
      final Phase4Exception aSendingEx = aSendingExceptionKeeper.get ();
      if (aSendingEx != null)
      {
        if (aSendingEx.getCause () instanceof ExtendedHttpResponseException)
        {
          final ExtendedHttpResponseException exr = (ExtendedHttpResponseException) aSendingEx.getCause ();
          LOGGER.error ("Error sending Peppol message via AS4 due to HTTP status code " + exr.getStatusCode ());
        }
        else
          LOGGER.error ("Exception sending AS4 user message", aSendingEx);
      }

    The ExtendedHttpResponseException has access to other parts of the HTTP response as well

ri4a commented 2 months ago

Fantastic Philip, thank you!