1. @override
void willSendResponse(Response response)

Executed prior to Response being sent.

This method is used to post-process response just before it is sent. By default, does nothing. The response may be altered prior to being sent. This method will be executed for all requests, including server errors.

Source

@override
void willSendResponse(Response response) {
  if (response.statusCode == 400) {
    if (response.body != null &&
        response.body["error"] ==
            "Duplicate parameter for non-List parameter type") {
      // This post-processes the response in the case that duplicate parameters
      // were in the request, which violates oauth2 spec. It just adjusts the error message.
      // This could be hardened some.
      response.body = {
        "error":
            AuthServerException.errorString(AuthRequestError.invalidRequest)
      };
    }
  }
}