Open Source API Gateway

500 Internal Server Error: setProperty Expression Failed

Membrane API Gateway returns 500 Internal Server Error when the setProperty plugin cannot evaluate its value expression. This works in the request flow and in the response flow. The problem is usually the expression in the gateway configuration, or a message that does not have the shape the expression expects.

The Error Response

The response contains the status 500 Internal Server Error, the problem type https://membrane-api.io/problems/internal and a link to this page. The title names the expression and the property that could not be set, so it differs from API to API. In development mode, the detail and the internal expression and field fields say which expression failed and why. The type internal means that the gateway could not complete the processing of the message. In production mode, the title is replaced by Internal Server Error and the details are left out.

What the setProperty Plugin Does

The setProperty plugin sets a property named name to the result of the value expression. The expression uses SpEL by default; with language you can select Groovy, JsonPath or XPath instead.

Common Causes

The Expression Fails at Runtime

The expression references a property, header or method that does not exist, or contains a syntax error in the selected language.

The Body Does Not Match the Expression Language

A JsonPath expression is evaluated on a body that is not JSON, or an XPath expression on a body that is not XML.

An Unexpected Exception in the Plugin

The same link also appears when the setProperty plugin throws an exception that it does not turn into an error response itself. Membrane then aborts the exchange with 500 Internal Server Error, and the detail reads Aborting! Exception caused in setproperty during … flow. with the request URI and the flow. Membrane logs every occurrence with the full stack trace. Unless the exception points to your configuration or to the message content, this usually indicates a bug in Membrane.

How to Fix It

  1. Read the detail and the internal expression and field fields of the response in development mode.
  2. Correct the expression, or make it handle missing data, for example with a default value.
  3. If the property is optional, set failOnError: false. The plugin then logs the error and continues without setting the property.
  4. If clients must send a specific body format, validate it earlier in the flow, for example with a validator, so that they get a 4xx instead.

This setProperty does not stop the request when the JSON field is missing:

api:
port: 2000
flow:
- request:
- setProperty:
name: city
value: ${$.address.city}
language: jsonpath
failOnError: false
target:
url: https://api.predic8.de
api:
  port: 2000
  flow:
    - request:
        - setProperty:
            name: city
            value: ${$.address.city}
            language: jsonpath
            failOnError: false
  target:
    url: https://api.predic8.de

Hide Details in Production

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: true
configuration:
  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 the details and the link to this page are left out. If the response contains a log key, search the gateway log for it to find the full error message.

If the plugin is nested inside a request, response or abort element and fails with an unexpected exception there, 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.

Related Documentation

Configuration reference:

Tutorials with runnable examples:

← All Membrane error messages

Still stuck? See the troubleshooting guide or ask on GitHub Issues. For commercial support, contact info@predic8.de.