Skip to content

Commit

Permalink
Return typed errors in object.Keystore.Decode func
Browse files Browse the repository at this point in the history
And map them to http status codes in the
GET /object/path/.../kvstore/entry api handler.

	KeystoreErrNotExist => 404
	KeystoreErrKeyEmpty => 400
  • Loading branch information
cvaroqui committed Sep 6, 2024
1 parent ea58be3 commit 3ae85fb
Show file tree
Hide file tree
Showing 6 changed files with 201 additions and 183 deletions.
4 changes: 2 additions & 2 deletions core/object/keystore_decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ func (t *keystore) decode(keyname string) ([]byte, error) {
err error
)
if keyname == "" {
return []byte{}, fmt.Errorf("key name can not be empty")
return []byte{}, KeystoreErrKeyEmpty
}
if !t.HasKey(keyname) {
return []byte{}, fmt.Errorf("key does not exist: %s", keyname)
return []byte{}, fmt.Errorf("%w: %s", KeystoreErrNotExist, keyname)
}
k := keyFromName(keyname)
if s, err = t.config.GetStrict(k); err != nil {
Expand Down
2 changes: 2 additions & 0 deletions core/oxcmd/keystore_decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ func (t *CmdKeystoreDecode) RunForPath(ctx context.Context, c *client.T, path na
return fmt.Errorf("%s: %s", path, *response.JSON403)
case http.StatusInternalServerError:
return fmt.Errorf("%s: %s", path, *response.JSON500)
case http.StatusNotFound:
return fmt.Errorf("%s: %s", path, *response.JSON404)
default:
return fmt.Errorf("%s: unexpected response: %s", path, response.Status())
}
Expand Down
2 changes: 2 additions & 0 deletions daemon/api/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2400,6 +2400,8 @@ paths:
$ref: '#/components/responses/401'
403:
$ref: '#/components/responses/403'
404:
$ref: '#/components/responses/403'
500:
$ref: '#/components/responses/500'

Expand Down
8 changes: 8 additions & 0 deletions daemon/api/codegen_client_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 3ae85fb

Please sign in to comment.