Skip to content
Node: http-errorsgithub.com/sahilkhaire/gox/err

AppError.Wrap

Overview

Wrap wraps cause with code and message.

Part of the err package — Node.js analog: http-errors.

Method on AppError — call it on a value of that type after constructing or receiving one from a constructor.

Signature

go
func Wrap(code int, message string, cause error) *AppError

Compare: Node.js · Standard Go · gox

js
// Typical http-errors pattern in Node.js
go
errors.Is(err, target)
errors.As(err, &target)
fmt.Errorf("context: %w", err)
go
import "github.com/sahilkhaire/gox/err"

return err.AppError.Wrap(cause, 500, "internal error")

Example

go
import "github.com/sahilkhaire/gox/err"

return err.AppError.Wrap(cause, 500, "internal error")

Tips

Obtain a AppError value first (see constructors on the package overview), then call Wrap.

Standard library alternative

Use the standard library directly:

go
errors.Is(err, target)
errors.As(err, &target)
fmt.Errorf("context: %w", err)

Back to err package overview

MIT Licensed · Built for Node.js developers moving to Go