Skip to content

Commit

Permalink
add missing json errors. (#1755)
Browse files Browse the repository at this point in the history
  • Loading branch information
efectn committed Feb 6, 2022
1 parent c450072 commit ad1a925
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
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)
}

0 comments on commit ad1a925

Please sign in to comment.