Hi, I’ve developed a Go plugin that transforms incoming requests before they reach the upstream server. This transformation involves querying a third-party service, which may occasionally respond with error status codes (400, 404, 422, 500, etc.). When an error occurs, the Go plugin returns the third party service’s response (including the body and status code) directly to the client, bypassing the upstream server. However, the Tyk API Gateway modifies my response with its own response handler, as it seems to interpret the plugin’s execution as an error.
This is the response body received by the client:
{
"code": "INVALID_INPUT",
"message": "Invalid request parameters",
"details": [
{
"field": "code",
"message": "Field required"
}
]
}{
"error": "plugin function sent error response code: 400"
}
The message “error”: “plugin function sent error response code: 400” has been added by Tyk itself, because of its built-in Response Handler: tyk/gateway/res_handler_go_plugin.go at 64c2a7fa7bcebe71e32f8465b02e43f078ff6ddd · TykTechnologies/tyk · GitHub.
I don’t want to return this information to the client; is there a configuration setting in Tyk to disable the default response handler? As custom plugins are described as supporting virtual endpoints in the documentation, I’m expecting them to function without interference from the default response handler.
This is my code:
if statusCode >= 400 {
fmt.Printf("Response from %s: status code %d\n", postURL, statusCode)
responseJSON, err := json.Marshal(newResponse)
if err != nil {
fmt.Println("Error in converting response to JSON:", err)
http.Error(rw, "Internal Server Error", http.StatusInternalServerError)
return
}
rw.Header().Set("Content-Type", "application/json")
rw.WriteHeader(statusCode)
rw.Write(responseJSON)
return
}
Thank you for the support!