SoftwareSandbox / Fiazard

Learning project in which we try to make our sandwich ordering site better. This is the backend project, providing RESTful webservices with DropWizard.
Apache License 2.0
2 stars 10 forks source link

Thrown Exception should be transformed into errors in JSON #5

Closed Sch3lp closed 9 years ago

Sch3lp commented 9 years ago

An Error should look like this:

{
   "errorCode":"AE1",
   "message":"You done broke it",
   "fields":["name","category"]
}

All thrown exceptions should be transformed into an error like that. We should have specific FiazardException classes to represent specific errors, but we'll add those when we require them. Just add one as an example for now.

Use a ExceptionMapper<FiazardException> for this purpose and register this as a Provider to your dropwizard environment.

Sch3lp commented 9 years ago

Attempted writing an IntegrationTest using the DropwizardAppRule, and we'd need to somehow be able to register a Resource that would be "configurable" during test run. This won't work since it's an @ClassRule and the DropwizardApp is already up and running even when you enter your own @BeforeClass initialization block.

So, the only way we can integration test this is by checking all specific Exceptions that can get thrown on all specific resource methods. Or be content with just unit testing the ExceptionToJSONMapper which'll do the actual work anyway. We could add to that a unit test that checks that this mapper is registered as a provider on a running FiazardApp instance.