api

package
v0.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 29, 2024 License: MIT Imports: 4 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrorHandler = func(c *fiber.Ctx, err error) error {
		c.Set(
			fiber.HeaderContentType,
			fiber.MIMETextPlainCharsetUTF8,
		)

		// Tries to parse 'error' as 'APIError'
		var e *Error

		if !errors.As(err, &e) {

			return c.Status(500).JSON(fiber.Map{
				"error": err.Error(),
			})
		}

		var (
			code     = e.Code
			code_str = utils.StatusMessage(code)
		)

		if e.Code == 0 || utils.StatusMessage(code) == "" {
			code = fiber.StatusInternalServerError
			code_str = "Internal Server Error"
		}

		return c.Status(code).JSON(fiber.Map{
			"code":    code_str,
			"message": e.Message,
		})
	}
)
View Source
var (
	RecommendedConfig = fiber.Config{
		JSONEncoder:  json.Marshal,
		JSONDecoder:  json.Unmarshal,
		ErrorHandler: ErrorHandler,
	}
)

Functions

This section is empty.

Types

type Error

type Error struct {
	Code    int
	Message string
}

func NewError

func NewError(code int, message string) *Error

func (*Error) Error

func (e *Error) Error() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL