grafana-plugin-sdk-go icon indicating copy to clipboard operation
grafana-plugin-sdk-go copied to clipboard

Errorsource's RoundTripper returns custom error alongside response

Open cletter7 opened this issue 1 year ago • 3 comments

It seems not ideal that the errorsource's round tripper returns custom generated error together with the response for certain status codes here: https://github.com/grafana/grafana-plugin-sdk-go/blob/main/experimental/errorsource/error_source_middleware.go#L21-L26

Because the Go http client ignores the response in case round tripper returns the error: https://github.com/golang/go/blob/6fe0d3758b35afcc342832e376d8d985a5a29070/src/net/http/client.go#L262-L264. The response body might contain useful information for the user.

cc @scottlepp

cletter7 avatar Dec 19 '23 09:12 cletter7

@cletter7 can you specify what is your expected return value?

academo avatar Feb 28 '24 08:02 academo

I am not sure if just changing the return value would help here. Ideally when I use errorsource middleware or htpp client I would like error source to be handled automatically, but at the same time I want to be able to access the response if there is response. The problem with the current approach is that response is lost when status code is >= 400. Maybe we need to extend/override http client later in the chain or use some other approach to achieve the desired result.

cletter7 avatar Feb 28 '24 10:02 cletter7

@scottlepp maybe you have something to add here?

cletter7 avatar Feb 28 '24 10:02 cletter7