You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe what are you trying to do:
I need to extract the statusCode field from the response body returned by the backend to replace the http stausCode returned to the user.
The structure of the response body returned by the backend looks like this:
When the backend api returns a business-customized exception, the http status code is usually 200, and I want the kranken D to return the statusCode in the return body as the http status code to the user.
I'm referring to the sample code provided by https://www.krakend.io/docs/enterprise/extending/plugin-modifiers/ and trying to make a substitution of the status code of the request and it doesn't seem to work. I was able to correctly parse the statusCode field of the returned message by setting output_encording=“json”, but it doesn't seem to be able to be set to an http status code!
typeresponseWrapperstruct {
ctx context.Contextrequestinterface{}
datamap[string]interface{}
isCompleteboolstatusCodeintheadersmap[string][]stringio io.Reader
}
func (rregisterer) responseDump(
cfgmap[string]interface{},
) func(interface{}) (interface{}, error) {
// return the modifierfmt.Println("response dumper injected!!!")
returnfunc(inputinterface{}) (interface{}, error) {
fmt.Println("response dumper injected!!!")
resp, _:=input.(proxy.ResponseWrapper)
modifiedResp:=responseWrapper{
data: resp.Data(),
io: resp.Io(),
isComplete: resp.IsComplete(),
headers: resp.Headers(),
statusCode: resp.StatusCode(),
}
ifresp!=nil {
fmt.Println("data:", resp.Data())
fmt.Println("is complete:", resp.IsComplete())
//Since output_encording is set to json, the output value here is always map[]fmt.Println("headers:", resp.Headers())
fmt.Println("statusCode:", resp.StatusCode())
//here I tried to modify its http status codemodifiedResp.statusCode=400fmt.Println("modified response statusCode:", modifiedResp.statusCode)
}
returnmodifiedResp, nil
}
Environment info:
Describe what are you trying to do:
I need to extract the statusCode field from the response body returned by the backend to replace the http stausCode returned to the user.
The structure of the response body returned by the backend looks like this:
When the backend api returns a business-customized exception, the http status code is usually 200, and I want the kranken D to return the statusCode in the return body as the http status code to the user.
I'm referring to the sample code provided by https://www.krakend.io/docs/enterprise/extending/plugin-modifiers/ and trying to make a substitution of the status code of the request and it doesn't seem to work. I was able to correctly parse the statusCode field of the returned message by setting output_encording=“json”, but it doesn't seem to be able to be set to an http status code!
Your configuration file:
I would very much appreciate advice.
The text was updated successfully, but these errors were encountered: