grafana-plugin-sdk-go
grafana-plugin-sdk-go copied to clipboard
Errorsource's RoundTripper returns custom error alongside response
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 can you specify what is your expected return value?
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.
@scottlepp maybe you have something to add here?