Adding "error" phase to plugin capabilities

I am using Go plugins to do a number of extensions to our usage of Tyk, and the number of different places I can hook Go plugins in the request lifecycle is incredibly helpful. However, as I’ve continued to build this out, it’s become apparent that there’s one “phase” missing in these hooks.

Go plugins (and probably others!) should be able to hook an “error” phase. That is, there are instances where Tyk itself generates and responds with an an error (as opposed to the proxied backend) in the flow of a request - i.e. the JWT was invalid, rate limit exceeded, the backend proxy was unavailable, etc. Currently this instance just responds with an error using the error templates, which is helpful, but nothing else functional can occur at those times, and any setup done during pre/post_key_auth/post etc phases just goes out the window without resolution. I think it would be incredibly helpful (and probably also really easy) to make the Tyk error handler able to fire a plugin phase if configured before responding with the actual error.

Thanks for the feedback. We will update this thread when there is an update to this request.