Skip to content

Add internal server error handler and tests#8

Merged
ctucker3 merged 1 commit intodevelopfrom
feature/INF-68
Apr 21, 2020
Merged

Add internal server error handler and tests#8
ctucker3 merged 1 commit intodevelopfrom
feature/INF-68

Conversation

@ctucker3
Copy link
Contributor

@ctucker3 ctucker3 commented Apr 16, 2020

This feature creates an ID for internal server errors and prints them to the logs so that we are able to debug the errors later.

Design Concepts

I used the micronaut custom error handling ability to catch all unhandled exceptions that are returned from the controllers. When we receive the unhandled exception, a UUID is created and logged with stack trace of the error. An internal server error response with the error UUID is then returned.

https://guides.micronaut.io/micronaut-error-handling/guide/index.html

Exceptions that are thrown in the services and handled in the controllers are not affected. By handling all unhandled exceptions, we can remove the custom DataAccessException handling that we were doing on all controller code and also expand the types errors we are able to trace.

Only getAll() and getById() in the ProgramController have been modified to account for the new error handling so far. There is another card to convert the existing controllers over to the new error handling method.

https://trello.com/c/D5WB7q1J/183-inf-69-update-controllers-to-throw-custom-web-exception-to-ensure-logging-is-consistent

Once this pull request is merged, the other controller methods will be converted.

Review Considerations

  • Is testing coverage complete?
  • Does the design make sense?

Note: This feature breaks two DataAcessException unit tests getProgramsAllDataAccessException and getProgramsSingleDataAccessException. This is because the getById and getAll functions were converted to the new error handling code as an example. These tests will be removed in INF-69.

@ctucker3
Copy link
Contributor Author

Copy link

@eawoods eawoods left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Builds well and it is easy to find the new error logs in surefire-reports.
One test fails with two errors in ProgramControllerUnitTest:

-------------------------------------------------------------------------------
Test set: org.breedinginsight.api.v1.controller.ProgramControllerUnitTest
-------------------------------------------------------------------------------
Tests run: 13, Failures: 0, Errors: 2, Skipped: 0, Time elapsed: 0.576 sec <<< FAILURE! - in org.breedinginsight.api.v1.controller.ProgramControllerUnitTest
getProgramsAllDataAccessException  Time elapsed: 0.01 sec  <<< ERROR!
org.jooq.exception.DataAccessException: TEST
	at org.breedinginsight.api.v1.controller.ProgramControllerUnitTest.getProgramsAllDataAccessException(ProgramControllerUnitTest.java:68)

getProgramsSingleDataAccessException  Time elapsed: 0.003 sec  <<< ERROR!
org.jooq.exception.DataAccessException: TEST
	at org.breedinginsight.api.v1.controller.ProgramControllerUnitTest.getProgramsSingleDataAccessException(ProgramControllerUnitTest.java:61)

According to Chris this is a known error that is fixed in a subsequent PR. Approving, to move on.

@ctucker3 ctucker3 merged commit 19828fe into develop Apr 21, 2020
@ctucker3 ctucker3 deleted the feature/INF-68 branch April 21, 2020 19:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants