Skip to content

Commit

Permalink
Adding error to protocol result if not 200 status code (#686)
Browse files Browse the repository at this point in the history
* Adding error to result if not 200

Signed-off-by: Daniel Grist <dgrist@ibm.com>

* Moving logic to Send()

Signed-off-by: Daniel Grist <dgrist@ibm.com>

* Checking for ACK

Signed-off-by: Daniel Grist <dgrist@ibm.com>
  • Loading branch information
danielgrist authored May 24, 2021
1 parent 27c75f8 commit 43b8eca
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion v2/protocol/http/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package http

import (
"bytes"
"context"
"errors"
"fmt"
Expand Down Expand Up @@ -139,7 +140,18 @@ func (p *Protocol) Send(ctx context.Context, m binding.Message, transformers ...
return fmt.Errorf("nil Message")
}

_, err := p.Request(ctx, m, transformers...)
msg, err := p.Request(ctx, m, transformers...)
if err != nil && !protocol.IsACK(err) {
var res *Result
if protocol.ResultAs(err, &res) {
if message, ok := msg.(*Message); ok {
buf := new(bytes.Buffer)
buf.ReadFrom(message.BodyReader)
errorStr := buf.String()
err = NewResult(res.StatusCode, "%s", errorStr)
}
}
}
return err
}

Expand Down

0 comments on commit 43b8eca

Please sign in to comment.