krakend / krakend-lua

a lua interpreter for the KrakenD framework
Apache License 2.0
7 stars 14 forks source link

Get body response to customize error code #27

Closed gmatera closed 2 years ago

gmatera commented 2 years ago

Hi all, as write in a title, my goal would be get the body response and check to customize the error to display. But at the moment I can't take the json present in the body (and displayed in postman) in no way.

thi is my krakend.json:

{
    "version": 2,
    "name": "krakend",
    "port": 8080,
    "timeout": "30000ms",
    "cache_ttl": "300s",
    "extra_config": {
  "github_com/devopsfaith/krakend-gologging": {
      "level":  "DEBUG",
      "prefix": "[KRAKEND]",
      "syslog": true,
      "stdout": true
  }
  },
  "endpoints": [
    {
        "endpoint": "/models/{group-id}",
        "extra_config": {
          "github.com/devopsfaith/krakend-lua/proxy": {
              "sources": [
            "file1.lua"
              ],
              "post": "extract_from_embedded(response.load(), errorKey)",
              "live": true,
              "allow_open_libs": true
          }
            },
            "github.com/devopsfaith/krakend/http": {
                          "return_error_details": "backend_models"
                      },
        "encoding": "no-op",
        "headers_to_pass":["*"],
        "querystring_params":["*"],
        "backend": [
      {
          "host": ["http://www.mydomain.com"],
          "url_pattern": "/api/jsonws/intouch-integration-api-portlet.modelapihelper/get-models-by-group/group-id/{group-id}",
          "group": "group_models"
      }
        ]
    }
  ]
}

and this is my lua function

function extract_from_embedded(response, errorKey)
    print("***")
    print(response:body())
end

Could you please help me

alombarte commented 2 years ago

Already posted here https://stackoverflow.com/questions/71081217/lua-script-for-krakend

github-actions[bot] commented 2 years ago

This issue was marked as resolved a long time ago and now has been automatically locked as there has not been any recent activity after it. You can still open a new issue and reference this link.