Membrane API Gateway returns 500 Internal Server Error with the detail Could not connect to database when the statisticsProvider plugin cannot get a connection from its JDBC data source. The database or the data source configuration is to blame.
The response contains the status 500 Internal Server Error, the title Internal server error., the detail Could not connect to database, the problem type https://membrane-api.io/problems/internal and a link to this page. In development mode, the message of the database exception is included as well. The type internal means that the gateway could not complete the processing of the exchange. In production mode, the title is replaced by Internal Server Error and the details are left out.
The statisticsProvider plugin reads the call statistics that Membrane stored in a database and returns them as JSON. It uses the JDBC data source bean named in dataSourceBeanId. If no connection can be obtained from that data source, the plugin answers with this error.
The database server is not running, or the gateway host cannot reach it because of DNS, firewall or port settings.
The data source bean has a wrong JDBC URL, user name or password, or its JDBC driver is not on the classpath of the gateway.
All connections of the data source's pool are in use, or the connection attempt timed out.
Any other exception that the statisticsProvider plugin does not turn into an error response itself is reported under the same URL by Membrane's generic error handler. The detail then reads Aborting! Exception caused in … flow. and names the plugin, the request URI and the flow. Unless the exception points to your configuration or to the message, this usually indicates a bug in Membrane.
dataSourceBeanId, and make sure the JDBC driver is available.By default, Membrane runs in development mode and adds details to error responses that help you find the problem. These details may reveal information about your setup. In production, turn them off:
configuration:
production: trueconfiguration: production: true
Add the configuration document to your apis.yaml and separate it from the APIs with ---. The title then reads Internal Server Error, and instead of the details the response only contains a log key. Search the gateway log for this key to find the exception.
If the plugin is nested inside a request, response or abort element and throws an unexpected exception, the exception message, the stack trace and the link to this page are currently sent even in production mode. Fix the failing plugin rather than relying on production mode to hide them.
Configuration reference:
Still stuck? See the troubleshooting guide or ask on GitHub Issues. For commercial support, contact info@predic8.de.