Custom error messages for plugins

#1

We want to use Kong to put in front of our API’s. Our API’s use a specific format for reporting errors to the API-users.

I’ve noticed that the response format from the plugins isn’t following any general line.
e.g. the OAuth plugin returns

{
    "error_description": "The access token is missing",
    "error": "invalid_request"
}

and the rate limiting plugin returns:

{
    "message": "API rate limit exceeded"
}

I would like these messages to be unified, and to follow my internal structure (makes it easier to parse for clients).

My internal structure, just for the sake of it:

{
	status: 429,
	message: "API rate limit exceeded",
	code: ECODEINTEXT
}

I would like to know if there is an easy way to customize the error messages of the plugins, without having to create all custom versions of the plugins.

#2

My suggestion would be a different one: write a single custom plugin which transforms the responses. That is completely possible in Kong.

This would allow you to update the plugins you use without having to maintain your own forks.

#3

Hi Kikito, Can you suggest or example about write plugin custom tranformation?