Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 add missing json errors #1755

Merged
merged 1 commit into from Feb 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 26 additions & 1 deletion error.go
@@ -1,6 +1,9 @@
package fiber

import "github.com/gofiber/fiber/v2/internal/schema"
import (
"github.com/gofiber/fiber/v2/internal/go-json/errors"
"github.com/gofiber/fiber/v2/internal/schema"
)

type (
// Conversion error exposes the internal schema.ConversionError for public use.
Expand All @@ -12,3 +15,25 @@ type (
// MultiError error exposes the internal schema.MultiError for public use.
MultiError = schema.MultiError
)

type (
// An InvalidUnmarshalError describes an invalid argument passed to Unmarshal.
// (The argument to Unmarshal must be a non-nil pointer.)
InvalidUnmarshalError = errors.InvalidUnmarshalError

// A MarshalerError represents an error from calling a MarshalJSON or MarshalText method.
MarshalerError = errors.MarshalerError

// A SyntaxError is a description of a JSON syntax error.
SyntaxError = errors.SyntaxError

// An UnmarshalTypeError describes a JSON value that was
// not appropriate for a value of a specific Go type.
UnmarshalTypeError = errors.UnmarshalTypeError

// An UnsupportedTypeError is returned by Marshal when attempting
// to encode an unsupported value type.
UnsupportedTypeError = errors.UnsupportedTypeError

UnsupportedValueError = errors.UnsupportedValueError
)
37 changes: 37 additions & 0 deletions error_test.go
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"testing"

jerrors "github.com/gofiber/fiber/v2/internal/go-json/errors"
"github.com/gofiber/fiber/v2/internal/schema"
"github.com/gofiber/fiber/v2/utils"
)
Expand All @@ -27,3 +28,39 @@ func TestMultiError(t *testing.T) {
ok := errors.As(MultiError{}, &schema.MultiError{})
utils.AssertEqual(t, true, ok)
}

func TestInvalidUnmarshalError(t *testing.T) {
var e *jerrors.InvalidUnmarshalError
ok := errors.As(&InvalidUnmarshalError{}, &e)
utils.AssertEqual(t, true, ok)
}

func TestMarshalerError(t *testing.T) {
var e *jerrors.MarshalerError
ok := errors.As(&MarshalerError{}, &e)
utils.AssertEqual(t, true, ok)
}

func TestSyntaxError(t *testing.T) {
var e *jerrors.SyntaxError
ok := errors.As(&SyntaxError{}, &e)
utils.AssertEqual(t, true, ok)
}

func TestUnmarshalTypeError(t *testing.T) {
var e *jerrors.UnmarshalTypeError
ok := errors.As(&UnmarshalTypeError{}, &e)
utils.AssertEqual(t, true, ok)
}

func TestUnsupportedTypeError(t *testing.T) {
var e *jerrors.UnsupportedTypeError
ok := errors.As(&UnsupportedTypeError{}, &e)
utils.AssertEqual(t, true, ok)
}

func TestUnsupportedValeError(t *testing.T) {
var e *jerrors.UnsupportedValueError
ok := errors.As(&UnsupportedValueError{}, &e)
utils.AssertEqual(t, true, ok)
}