Skip to content

Commit

Permalink
new error type
Browse files Browse the repository at this point in the history
  • Loading branch information
chadlagore committed Jul 15, 2017
1 parent 3affb8e commit f8ec541
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
8 changes: 4 additions & 4 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ func RequestHandler(req *msg.Request) msg.Response {
// Build some error types.
typeErr := msg.NewProtocolError(msg.InvalidResourceType,
"Invalid resource type")
paramErr := msg.NewProtocolError(msg.InvalidResourceType,
"Invalid request parameter, blockNumber must be uint32.")
notFoundErr := msg.NewProtocolError(msg.ResourceNotFound,
"Resource not found.")

switch req.ResourceType {
case msg.ResourcePeerInfo:
Expand All @@ -143,13 +143,13 @@ func RequestHandler(req *msg.Request) msg.Response {
blk, err := chain.CopyBlockByIndex(blockNumber)
if err != nil {
// Bad index parameter.
res.Error = paramErr
res.Error = notFoundErr
} else {
res.Resource = blk
}
} else {
// No index parameter.
res.Error = paramErr
res.Error = notFoundErr
}
default:
// Return err by default.
Expand Down
2 changes: 2 additions & 0 deletions msg/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ const (
// InvalidResourceType occurs when a request is received with an unknown
// ResourceType value.
InvalidResourceType = 401
// ResourceNotFound occurs when a node reports the requested resource missing.
ResourceNotFound = 404
// NotImplemented occurs when a message or request is received whos response
// requires functionality that does not yet exist.
NotImplemented = 501
Expand Down
2 changes: 1 addition & 1 deletion pool/pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func TestNextBlock(t *testing.T) {
}
b := p.NextBlock(chain, blockchain.NewWallet().Public(), 1<<18)
assert.NotNil(t, b)
assert.True(t, b.Len() < blockchain.UserBlockSize)
assert.True(t, b.Len() < 1<<18)
assert.True(t, b.Len() > 0)

// The difference is off by one thanks to cloud transaction.
Expand Down

0 comments on commit f8ec541

Please sign in to comment.