Skip to content
Node: createError(401, msg)github.com/sahilkhaire/gox/err

AppError.Unauthorized

Overview

Unauthorized returns a 401 AppError.

If you are coming from Node.js, the closest pattern is createError(401, msg).

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

Signature

go
func Unauthorized(message string) *AppError

Compare: Node.js · Standard Go · gox

js
next(createError(401, 'unauthorized'));
go
return fmt.Errorf("%w: message", http.ErrUnauthorized)
go
import "github.com/sahilkhaire/gox/err"

return err.Unauthorized("unauthorized")

Example

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

return err.Unauthorized("unauthorized")

Tips

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

Standard library alternative

Use the standard library directly:

go
return fmt.Errorf("%w: message", http.ErrUnauthorized)

Back to err package overview

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