httperr

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2022 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package httperr contains the helper for extracting HTTP status code from a semerr.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Code

func Code(err error) int

Code returns http status code for err.

Example
package main

import (
	"errors"
	"fmt"
	"net/http"

	"github.com/hedhyw/semerr/pkg/v1/httperr"
	"github.com/hedhyw/semerr/pkg/v1/semerr"
)

func main() {
	err := semerr.NewBadRequestError(errors.New("bad request error"))

	fmt.Println(
		"Is err bad request?",
		httperr.Code(err) == http.StatusBadRequest,
	)
}
Output:

Is err bad request? true

func Wrap added in v0.5.0

func Wrap(err error, code int) error

Wrap wraps the `err` with an error corresponding to the `code`. If there is no `err` for this code then the `err` will be returned without wrapping.

Types

This section is empty.

Jump to

Keyboard shortcuts

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