forked from TrueCloudLab/frostfs-rest-gw
[#15] Use extended error response
Signed-off-by: Denis Kirillov <denis@nspcc.ru>
This commit is contained in:
parent
e28c6e5375
commit
9fba8d7f23
22 changed files with 528 additions and 174 deletions
27
internal/util/transformers_test.go
Normal file
27
internal/util/transformers_test.go
Normal file
|
@ -0,0 +1,27 @@
|
|||
package util
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestErrors(t *testing.T) {
|
||||
apiErr := fmt.Errorf("some context: %w", apistatus.ContainerNotFound{})
|
||||
|
||||
resp := NewErrorResponse(apiErr)
|
||||
data, err := json.Marshal(resp)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, `{"code":3072,"message":"some context: status: code = 3072","type":"API"}`, string(data))
|
||||
|
||||
gwErr := fmt.Errorf("some context: %w", errors.New("sanity check error"))
|
||||
|
||||
resp = NewErrorResponse(gwErr)
|
||||
data, err = json.Marshal(resp)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, `{"message":"some context: sanity check error","type":"GW"}`, string(data))
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue