add missing json errors. (#1755)

pull/1764/head
M. Efe Çetin 2022-02-06 23:28:02 +03:00 committed by GitHub
parent c450072f4a
commit ad1a925d38
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 63 additions and 1 deletions

View File

@ -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.
@ -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
)

View File

@ -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"
)
@ -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)
}