Skip to content
This repository has been archived by the owner on May 6, 2024. It is now read-only.

Commit

Permalink
proxy synchronous service errors to client (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
petar authored Apr 27, 2022
1 parent fb1b15c commit 52aae19
Show file tree
Hide file tree
Showing 6 changed files with 1,382 additions and 1,237 deletions.
15 changes: 15 additions & 0 deletions blueprints/services/dagjson-over-http/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,21 @@ func (c *{{.Type}}) {{.AsyncMethodDecl}} {
c.ulk.Unlock()
return nil, {{.ErrSchema}}
}
// HTTP codes other than 200 correspond to service implementation rejecting the call when it is received
// for reasons unrelated to protocol schema
if resp.StatusCode != 200 {
resp.Body.Close()
if resp.Header != nil {
if errValues, ok := resp.Header["Error"]; ok && len(errValues) == 1 {
err = {{.ErrService}}{Cause: {{.Errorf}}("%s", errValues[0])}
} else {
err = {{.Errorf}}("service rejected the call, no cause provided")
}
} else {
err = {{.Errorf}}("service rejected the call")
}
return nil, err
}
ch := make(chan {{.MethodReturnAsync}}, 1)
go {{.ProcessReturnAsync}}(ctx, ch, resp.Body)
Expand Down
3 changes: 2 additions & 1 deletion blueprints/services/dagjson-over-http/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ func (x GoServerImpl) GoDef() cg.Blueprint {
case env.{{.MethodName}} != nil:
ch, err := s.{{.MethodName}}({{.ContextBackground}}(), env.{{.MethodName}})
if err != nil {
{{.LoggerVar}}.Errorf("get p2p provider rejected request (%v)", err)
{{.LoggerVar}}.Errorf("service rejected request (%v)", err)
writer.Header()["Error"] = []string{err.Error()}
writer.WriteHeader(500)
return
}
Expand Down
Loading

0 comments on commit 52aae19

Please sign in to comment.