-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[RHCLOUD-36917] add Kessel error details into notifications history (#…
- Loading branch information
Showing
6 changed files
with
89 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
...src/main/java/com/redhat/cloud/notifications/connector/email/EmailExceptionProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.redhat.cloud.notifications.connector.email; | ||
|
||
import com.redhat.cloud.notifications.connector.http.HttpExceptionProcessor; | ||
import jakarta.annotation.Priority; | ||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.enterprise.inject.Alternative; | ||
import org.apache.camel.Exchange; | ||
import org.apache.camel.http.base.HttpOperationFailedException; | ||
|
||
import static com.redhat.cloud.notifications.connector.email.constants.ExchangeProperty.ADDITIONAL_ERROR_DETAILS; | ||
|
||
@ApplicationScoped | ||
@Alternative | ||
@Priority(0) // The value doesn't matter. | ||
public class EmailExceptionProcessor extends HttpExceptionProcessor { | ||
|
||
@Override | ||
protected void process(Throwable t, Exchange exchange) { | ||
super.process(t, exchange); | ||
if (t instanceof HttpOperationFailedException e) { | ||
exchange.setProperty(ADDITIONAL_ERROR_DETAILS, e.getResponseBody()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
...in/java/com/redhat/cloud/notifications/recipients/rest/WebApplicationExceptionMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.redhat.cloud.notifications.recipients.rest; | ||
|
||
import com.fasterxml.jackson.core.JsonParseException; | ||
import io.quarkus.logging.Log; | ||
import jakarta.ws.rs.BadRequestException; | ||
import jakarta.ws.rs.WebApplicationException; | ||
import jakarta.ws.rs.core.Response; | ||
import jakarta.ws.rs.ext.ExceptionMapper; | ||
import jakarta.ws.rs.ext.Provider; | ||
|
||
import static jakarta.ws.rs.core.Response.Status.BAD_REQUEST; | ||
|
||
@Provider | ||
public class WebApplicationExceptionMapper implements ExceptionMapper<WebApplicationException> { | ||
|
||
|
||
/** | ||
* Map thrown Exceptions to Responses with appropriate status codes | ||
*/ | ||
@Override | ||
public Response toResponse(WebApplicationException exception) { | ||
Log.error(exception); | ||
if (exception instanceof BadRequestException) { | ||
return Response.status(BAD_REQUEST).entity(exception.getMessage()).build(); | ||
} | ||
if (exception.getCause() != null && exception.getCause() instanceof JsonParseException) { | ||
JsonParseException jsonParseException = (JsonParseException) exception.getCause(); | ||
return Response.status(BAD_REQUEST).entity(jsonParseException.getMessage()).build(); | ||
} | ||
return Response.status(exception.getResponse().getStatus()).entity(exception.getMessage()).build(); | ||
} | ||
} |