-
Notifications
You must be signed in to change notification settings - Fork 773
refactor: use package server/api to register supernode's API #1366
Conversation
3e559bd
to
69f815a
Compare
69f815a
to
f0671e5
Compare
Codecov Report
@@ Coverage Diff @@
## master #1366 +/- ##
==========================================
+ Coverage 52.02% 52.26% +0.24%
==========================================
Files 137 136 -1
Lines 9108 9104 -4
==========================================
+ Hits 4738 4758 +20
+ Misses 3987 3961 -26
- Partials 383 385 +2
Continue to review full report at Codecov.
|
// | ||
// TODO: | ||
// Should the response body should be empty if the data is nil or empty | ||
// string? Now it's incompatible with the client. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should. If the data is nil/empty, it basically means there is an error somehow, in that case, the code
should reflect which error it is, and data should be used to show more detailed message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, maybe we should provide a method to send header only.
supernode/server/api/utils.go
Outdated
} | ||
|
||
// HandleErrorResponse handles err from server side and constructs response | ||
// for client side. | ||
func HandleErrorResponse(w http.ResponseWriter, err error) { | ||
switch e := err.(type) { | ||
case *errortypes.HTTPError: | ||
_ = EncodeResponse(w, e.Code, errResp(e.Code, e.Msg)) | ||
_ = SendResponse(w, e.Code, errResp(e.Code, e.Msg)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is odd, The error should not be ignored silently, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
b823c27
to
63832e8
Compare
supernode/server/router.go
Outdated
} | ||
|
||
// EncodeResponse encodes response in json. | ||
// SendResponse encodes response in json. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/ SendResponse/ EncodeResponse
@@ -47,6 +47,9 @@ func newCategory(name, prefix string) *category { | |||
apiCategories[name] = &category{ | |||
name: name, | |||
prefix: prefix, | |||
handlerSpecs: []*HandlerSpec{ | |||
listHandler(name), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why should we add a default list handler here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can help us to get all the available APIs provided by supernode.
Signed-off-by: lowzj <zj3142063@gmail.com>
63832e8
to
cd9fa36
Compare
LGTM. |
Signed-off-by: lowzj zj3142063@gmail.com
Ⅰ. Describe what this PR did
use package server/api to register supernode's APIs
Ⅱ. Does this pull request fix one issue?
Ⅲ. Why don't you add test cases (unit test/integration test)? (你真的觉得不需要加测试吗?)
Ⅳ. Describe how to verify it
Ⅴ. Special notes for reviews