Skip to content

Examples to show using errors pkg to handle error in multiple layered RESTful service

License

Notifications You must be signed in to change notification settings

y4code/error-handling-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Examples to show using errors pkg to handle error in multiple layered RESTful service

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages