How to change an Error Message from a Backend

This recipe demonstrates how to dynamically change a server's error response to a different format.
We will use Problem JSON as return format for this recipe.



For more information on inline expressions and scripting in Membrane, see: Scripting.

<api port="2000">
  <response>             <!-- Regex for 4XX -->
    <if test="statusCode matches '4.*'" language="spel">
      <template contentType="application/json">
          "type": "",
          "title": "${exc.response.statusMessage}",
          "status": ${exc.response.statusCode}
  <target url="localhost:2001" />

<api port="2001" name="mock server">
  <return statusCode="405" />


If Documentation Examples
Template Documentation Examples