AppError.BadRequest
Overview
BadRequest returns a 400 AppError.
If you are coming from Node.js, the closest pattern is createError(400, msg).
Method on AppError — call it on a value of that type after constructing or receiving one from a constructor.
Signature
go
func BadRequest(message string) *AppErrorCompare: Node.js · Standard Go · gox
js
next(createError(400, 'bad request'));go
return fmt.Errorf("%w: message", http.ErrBadRequest)go
import "github.com/sahilkhaire/gox/err"
return err.BadRequest("bad request")Example
go
import "github.com/sahilkhaire/gox/err"
return err.BadRequest("bad request")Tips
Obtain a AppError value first (see constructors on the package overview), then call BadRequest.
Standard library alternative
Use the standard library directly:
go
return fmt.Errorf("%w: message", http.ErrBadRequest)