Open Source API Gateway

500 Internal Server Error: Could Not Parse Query Parameters

Membrane API Gateway returns 500 Internal Server Error with the detail Could not parse query parameters! when the formValidation plugin cannot extract the parameters of a request. Membrane reports this as a 500, but the cause is usually the client's request.

The Error Response

The response contains the status 500 Internal Server Error, the detail Could not parse query parameters!, the offending request URI in the uri field, 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 request. In production mode, the title is replaced by Internal Server Error and the details are left out.

What the Form Validation Plugin Does

The formValidation plugin checks the parameters of the query string or of an application/x-www-form-urlencoded body against regular expressions, one per field. Before it can check them, it has to parse them. If parsing fails, this error is returned instead of a validation result.

Common Causes

A Parameter Occurs More Than Once

The plugin parses parameters strictly and rejects duplicates, e.g. ?age=1&age=2. The underlying message reads Could not parse query: ....

An Invalid Percent-Escape

A parameter contains an invalid percent-escape, e.g. %zz or a trailing %.

The Request URI Cannot Be Parsed

The request URI contains characters that Membrane's URI parser does not accept.

The Form Body Could Not Be Read

The body could not be read or decoded, for example because the client closed the connection during the upload or sent an unsupported Content-Encoding.

An Unexpected Exception in the Plugin

Any other exception thrown by the plugin 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 request, this usually indicates a bug in Membrane.

How to Fix It

  1. Client: send each form or query parameter only once, and percent-encode reserved characters correctly.
  2. Client: send a complete body and a Content-Encoding the gateway supports.
  3. Operator: the offending URI is in the uri field of the response. Enable development mode, or use the log key in production, to see the underlying exception.

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 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.

Related Documentation

Configuration reference:

← All Membrane error messages

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