grpcerr

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: 4 Imported by: 0

Documentation

Overview

Package grpcerr contains the helper for extracting gRPC status code from a semerr.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Code

func Code(err error) codes.Code

Code returns grpc status code for err.

Example
package main

import (
	"errors"
	"fmt"

	"github.com/hedhyw/semerr/pkg/v1/grpcerr"
	"github.com/hedhyw/semerr/pkg/v1/semerr"

	"google.golang.org/grpc/codes"
)

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

	fmt.Println(
		"Is err invalid argument?",
		grpcerr.Code(err) == codes.InvalidArgument,
	)
}
Output:

Is err invalid argument? true

func Wrap added in v0.5.0

func Wrap(err error, code codes.Code) 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