Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add NewErrorWithContext #578

Closed
wants to merge 3 commits into from
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion error.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,15 @@ var NewError = func(status int, msg string, errs ...error) StatusError {
}
}

var NewErrorWithContext = func(_ Context, status int, msg string, errs ...error) StatusError {
return NewError(status, msg, errs...)
}

// WriteErr writes an error response with the given context, using the
// configured error type and with the given status code and message. It is
// marshaled using the API's content negotiation methods.
func WriteErr(api API, ctx Context, status int, msg string, errs ...error) error {
var err any = NewError(status, msg, errs...)
var err any = NewErrorWithContext(ctx, status, msg, errs...)

ct, negotiateErr := api.Negotiate(ctx.Header("Accept"))
if negotiateErr != nil {
Expand Down