grpcerror

package module
v0.0.0-...-d450848 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2023 License: MIT Imports: 3 Imported by: 0

README

gRPC error

⭐ Star us on GitHub — it motivates us a lot!

gRPC error library for Go/Golang.

If you are a server developer, you should generate errors with enough information to help client developers understand and resolve the problem.

Table of Content

Error Payloads

The google.rpc package defines a set of standard error payloads, which are preferred to custom error payloads. The following table lists each error code and its matching standard error payload, if applicable. We recommend advanced applications look for these error payloads in google.rpc.Status when they handle errors.

HTTP gRPC Error detail
400 INVALID_ARGUMENT google.rpc.BadRequest
400 FAILED_PRECONDITION google.rpc.PreconditionFailure
400 OUT_OF_RANGE google.rpc.BadRequest
401 UNAUTHENTICATED google.rpc.ErrorInfo
403 PERMISSION_DENIED google.rpc.ErrorInfo
404 NOT_FOUND google.rpc.ResourceInfo
409 ABORTED google.rpc.ErrorInfo
409 ALREADY_EXISTS google.rpc.ResourceInfo
429 RESOURCE_EXHAUSTED google.rpc.QuotaFailure
499 CANCELLED
500 DATA_LOSS google.rpc.DebugInfo
500 UNKNOWN google.rpc.DebugInfo
500 INTERNAL google.rpc.DebugInfo
501 NOT_IMPLEMENTED
503 UNAVAILABLE google.rpc.DebugInfo
504 DEADLINE_EXCEEDED google.rpc.DebugInfo

Usage/Examples

NewNotFoundError
package main

import (
	"google.golang.org/genproto/googleapis/rpc/errdetails"

	"github.com/LipsarHQ/go-grpc-error"
)

func main() {
	// ...
	if err != nil {
		// Return error in case of resource not found.
		return nil, grpcerror.NewNotFoundError(&errdetails.ResourceInfo{
			ResourceType: "", // string(new(examplepb.Example).ProtoReflect().Descriptor().FullName())
			ResourceName: "", // ID.
			Owner:        "", // ID.
			Description:  err.Error(),
		})
	}
}

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewAbortedError

func NewAbortedError(pbErrorInfo *errdetails.ErrorInfo) (err error)

func NewAlreadyExistsError

func NewAlreadyExistsError(pbResourceInfo *errdetails.ResourceInfo) (err error)

func NewCanceledError

func NewCanceledError() (err error)

func NewDataLossError

func NewDataLossError(pbDebugInfo *errdetails.DebugInfo) (err error)

func NewDeadlineExceededError

func NewDeadlineExceededError(pbDebugInfo *errdetails.DebugInfo) (err error)

func NewInternalError

func NewInternalError(pbDebugInfo *errdetails.DebugInfo) (err error)

func NewInvalidArgumentError

func NewInvalidArgumentError(pbBadRequest *errdetails.BadRequest) (err error)

func NewNotFoundError

func NewNotFoundError(pbResourceInfo *errdetails.ResourceInfo) (err error)

func NewOutOfRangeError

func NewOutOfRangeError(pbBadRequest *errdetails.BadRequest) (err error)

func NewPermissionDeniedError

func NewPermissionDeniedError(pbErrorInfo *errdetails.ErrorInfo) (err error)

func NewPreconditionFailureError

func NewPreconditionFailureError(pbPreconditionFailure *errdetails.PreconditionFailure) (err error)

func NewResourceExhaustedError

func NewResourceExhaustedError(pbQuotaFailure *errdetails.QuotaFailure) (err error)

func NewUnauthenticatedError

func NewUnauthenticatedError(pbErrorInfo *errdetails.ErrorInfo) (err error)

func NewUnavailableError

func NewUnavailableError() (err error)

func NewUnimplementedError

func NewUnimplementedError() (err error)

func NewUnknownError

func NewUnknownError(pbDebugInfo *errdetails.DebugInfo) (err error)

Types

This section is empty.

Jump to

Keyboard shortcuts

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