I am using OpenAPI Generator in a C# project to generate a client which I can then use to interact with a Thingsboard instance and I just came across the exact same problem which someone else already described here: https://serveanswer.com/questions/how-should-you-implement-an-interceptresponse-method-to-handle-unauthorized-requests
In case the link breaks at a later point of time, here is a short summary of the issue:
I need to intercept all responses with a 401 Unauthorized header, get a new token and then retry the request. However, in the auto-generated ApiClient
class there are only the following two partial methods for intercepting requests/responses:
partial void InterceptRequest(IRestRequest request);
partial void InterceptResponse(IRestRequest request, IRestResponse response);
I already implemented everything necessary to catch 401 responses and refresh the token. The problem is that there does not seem to be any way for me to retry the request inside InterceptResponse
, because the response
is passed by value so I cannot modify it outside of InterceptResponse
. I cannot edit the method signatures either because they are auto-generated.
How am I supposed to deal with this so I do not have to manually check for a 401 response for every single request and then refresh the token and retry the request manually?