httperr

package
v0.6.6 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2023 License: MIT Imports: 4 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. In case of joined errors it returns the first code found in the chain.

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