Interface ErrorContext


  • public interface ErrorContext
    This library provides an easy way to store application errors in your service's local (e.g. Postgres) database. This interface defines the general contract, and instances are built using ErrorContextBuilder.

    This acts much like a Dropwizard bundle in that it creates an ApplicationErrorDao for use anywhere in your application, and registers an ApplicationErrorResource which exposes application errors via REST. The errorDao() method provides the DAO once an ErrorContext has been built by one of the build methods in ErrorContextBuilder.

    It also registers a health check that reports healthy if no errors have occurred in a configurable time window. The default value is the last 15 minutes. If desired, you can disable the creation of the health check by calling ErrorContextBuilder.skipHealthCheck() when constructing the instance.

    We currently support storing errors to a relational database with JDBI 3. If your application does not currently have a database or uses something else, then we also provide an option to use an in-memory H2 database.

    JDBI Note: To start creating application errors you will first need to create the database table (unless you are using the in-memory H2 database). See dropwizard-app-errors-migrations.xml in the source code for more details; this is a Liquibase migration file. Once the table exists, build an instance using ErrorContextBuilder. You can then supply the ApplicationErrorDao to anywhere in your application, e.g. other services or DAOs, resources, etc. Once your application has started, clients can retrieve and resolve application errors via the REST endpoint.

    See Also:
    ErrorContextBuilder
    Implementation Note:
    The reason this is not a Dropwizard bundle is mainly because it would not have the necessary components (such as a Dropwizard DataSourceFactory or JDBI 3 Jdbi instance) during the Dropwizard bundle initialization lifecycle.