Skip to content

Commit

Permalink
Fixing issue in event polling error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashi1993 committed Sep 21, 2023
1 parent d55811b commit 8d075b3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ public EventPollingResponse pollEvents(JSONObject eventPollingRequest) {
} catch (OBEventNotificationException e) {
log.error("Invalid client ID", e);
eventPollingResponse.setStatus(EventNotificationConstants.BAD_REQUEST);
eventPollingResponse.setErrorResponse(String.format("A client was not found" +
" for the client id : '%s' in the database.. ",
eventPollingDTO.getClientId()));
eventPollingResponse.setErrorResponse(EventNotificationServiceUtil.getErrorDTO(
EventNotificationConstants.INVALID_REQUEST, String.format("A client was not found" +
" for the client id : '%s' in the database.. ", eventPollingDTO.getClientId())));
return eventPollingResponse;
}

Expand All @@ -80,7 +80,8 @@ public EventPollingResponse pollEvents(JSONObject eventPollingRequest) {
} catch (OBEventNotificationException e) {
log.error("OB Event Notification error" , e);
eventPollingResponse.setStatus(EventNotificationConstants.BAD_REQUEST);
eventPollingResponse.setErrorResponse(e.getMessage());
eventPollingResponse.setErrorResponse(EventNotificationServiceUtil.getErrorDTO(
EventNotificationConstants.INVALID_REQUEST, e.getMessage()));
return eventPollingResponse;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class EventPollingResponse {

private String status;
private JSONObject responseBody;
private String errorResponse;
private Object errorResponse;

public String getStatus() {
return status;
Expand All @@ -45,11 +45,11 @@ public void setResponseBody(JSONObject responseBody) {
this.responseBody = responseBody;
}

public String getErrorResponse() {
public Object getErrorResponse() {
return errorResponse;
}

public void setErrorResponse(String errorResponse) {
public void setErrorResponse(Object errorResponse) {
this.errorResponse = errorResponse;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,25 +97,17 @@ public static Response mapEventCreationServiceResponse(EventCreationResponse eve
public static Response mapEventPollingServiceResponse(EventPollingResponse eventPollingResponse) {

if (EventNotificationConstants.OK.equals(eventPollingResponse.getStatus())) {

return Response.status(Response.Status.OK).entity(eventPollingResponse.getResponseBody()).build();

} else if (EventNotificationConstants.NOT_FOUND.equals(eventPollingResponse.getStatus())) {

return Response.status(Response.Status.NOT_FOUND).entity(EventNotificationUtils.getErrorDTO(
EventNotificationEndPointConstants.NOTIFICATIONS_NOT_FOUND,
EventNotificationEndPointConstants.NOT_FOUND_RESPONSE)).build();

} else if (EventNotificationConstants.BAD_REQUEST.equals(eventPollingResponse.getStatus())) {

return Response.status(Response.Status.BAD_REQUEST).entity(EventNotificationUtils.getErrorDTO(
EventNotificationEndPointConstants.INVALID_REQUEST,
eventPollingResponse.getErrorResponse())).build();
} else {
if (eventPollingResponse.getErrorResponse() instanceof String) {
return Response.status(Response.Status.BAD_REQUEST).entity(EventNotificationUtils.getErrorDTO(
EventNotificationEndPointConstants.INVALID_REQUEST,
eventPollingResponse.getErrorResponse().toString())).build();
} else {
return Response.status(Response.Status.BAD_REQUEST).entity(eventPollingResponse.getErrorResponse())
.build();
}
}

return Response.status(Response.Status.BAD_REQUEST).entity(EventNotificationUtils.getErrorDTO(
EventNotificationEndPointConstants.INVALID_REQUEST,
EventNotificationEndPointConstants.POLLING_ERROR_RESPONSE)).build();
}

/**
Expand Down

0 comments on commit 8d075b3

Please sign in to comment.