responsable-errors/new.go

38 lines
991 B
Go

package errors
import "net/http"
// Represents a 404 error.
func NewNotFound(format string, parts ...any) SettableError {
if format == "" {
format = "Not Found"
}
return Errorf(http.StatusNotFound, format, parts...)
}
// Represents a 400 error.
func NewBadRequest(format string, parts ...any) SettableError {
if format == "" {
format = "Bad Request"
}
return Errorf(http.StatusBadRequest, format, parts...)
}
// A 401 error with the error message "Unauthorized"
func NewUnauthorized() SettableError {
return Errorf(http.StatusUnauthorized, "Unauthorized")
}
// A 403 error with the error message "Forbidden"
func NewForbidden() SettableError {
return Errorf(http.StatusForbidden, "Forbidden")
}
// Represents a 500 error. For this error, the user error is preset to "Unknown Error".
func NewInternalError(format string, parts ...any) SettableError {
status := http.StatusInternalServerError
msg := "Unknown Error"
return Errorf(status, format, parts...).SetMsg(msg)
}