Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing issue in event polling error handling #20

Merged
merged 6 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
AmilaSamith marked this conversation as resolved.
Show resolved Hide resolved
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
Loading