Membrane API Gateway returns 500 Internal Server Error when the for plugin cannot evaluate its in expression against the current request or response. The fault is usually in the gateway configuration, sometimes in a message body that is not valid JSON or XML.
The response contains the status 500 Internal Server Error, a detail that describes the evaluation problem, the problem type https://membrane-api.io/problems/internal and a link to this page. The type internal means that the gateway could not complete the processing of the message. The error can occur in the request and in the response flow; in both cases the client receives a 500. In production mode, the title is replaced by Internal Server Error and the details are left out.
The for plugin evaluates the expression in in to a list and runs its nested flow once for every element, which is available as it. The expression language is set with language: spel, jsonpath, xpath or groovy.
api:
port: 2000
flow:
- for:
in: $.fruits
language: jsonpath
flow:
- setBody:
value: ${toJSON(it)}
- call:
method: POST
url: https://api.predic8.de/shop/v2/products
api:
port: 2000
flow:
- for:
in: $.fruits
language: jsonpath
flow:
- setBody:
value: ${toJSON(it)}
- call:
method: POST
url: https://api.predic8.de/shop/v2/products
See scripting with Groovy, JavaScript and SpEL for the expression languages.
The expression refers to a method that does not exist, fails at runtime (for example a property access on a null value), or yields a value that cannot be converted. The detail names the problem, e.g. Method not found in expression ... or Type converter not found .... If a Membrane built-in function fails, it is named in the function field of the response.
With language: jsonpath, the path is syntactically invalid (Invalid JSONPath.), or the body cannot be read as the expected JSON (Error evaluating JSONPath).
With language: xpath, the expression is invalid, uses a namespace prefix that is not declared, or the body has characters before the XML declaration or after the root element.
Any other exception thrown by the plugin, including a runtime error in a groovy expression, 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.
in expression and its language against the message the plugin receives in the flow where it is placed.xmlConfig of the enclosing API.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 response then 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, 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:
Tutorials with runnable examples:
Still stuck? See the troubleshooting guide or ask on GitHub Issues. For commercial support, contact info@predic8.de.