Always include the X-Stream-Error trailer (even without errors)

This is to potentially address things like this:

https://github.com/nodejs/undici/issues/432#issuecomment-1047931107
This commit is contained in:
Hector Sanjuan 2022-04-04 12:09:54 +02:00
parent a2b89f9b3b
commit 787aea5f31
2 changed files with 7 additions and 1 deletions

View File

@ -644,6 +644,10 @@ func (api *API) StreamResponse(w http.ResponseWriter, next StreamIterator, errCh
if err != nil {
w.Header().Set("X-Stream-Error", err.Error())
} else {
// Due to some Javascript-browser-land stuff, we set the header
// even when there is no error.
w.Header().Set("X-Stream-Error", "")
}
// check for function errors
for funcErr := range errCh {

View File

@ -156,7 +156,9 @@ func (c *defaultClient) handleStreamResponse(resp *http.Response, handler respon
trailerErrs := resp.Trailer.Values("X-Stream-Error")
var err error
for _, trailerErr := range trailerErrs {
err = multierr.Append(err, errors.New(trailerErr))
if trailerErr != "" {
err = multierr.Append(err, errors.New(trailerErr))
}
}
if err != nil {