error-handling-example

command module
v0.0.0-...-013927c Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2022 License: MIT Imports: 3 Imported by: 0

README

error-handling-example

Use errors pkg to handle error in mutiple layered RESTful service

Inpired by https://stackoverflow.com/questions/63306404/overriding-errors-is-not-working-with-custom-errors

method one

method_one.go

Use errors.As in top layer, handle the error created by errors.New in middle layers, as a result, the custom error will be "throw" from bottom layer to top layer

method two

main.go

Implement interface{ Is(error) bool } interface for custom error, and use errors.Is in top layer to determine if the error stack contains custom error

Suggest method two

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

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