mirror of
https://github.com/mjl-/mox.git
synced 2025-07-10 07:14:40 +03:00
mox!
This commit is contained in:
36
smtpserver/error.go
Normal file
36
smtpserver/error.go
Normal file
@ -0,0 +1,36 @@
|
||||
package smtpserver
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/mjl-/mox/smtp"
|
||||
)
|
||||
|
||||
func xcheckf(err error, format string, args ...any) {
|
||||
if err != nil {
|
||||
panic(smtpError{smtp.C451LocalErr, smtp.SeSys3Other0, fmt.Errorf("%s: %w", fmt.Sprintf(format, args...), err), true, false})
|
||||
}
|
||||
}
|
||||
|
||||
type smtpError struct {
|
||||
code int
|
||||
secode string
|
||||
err error
|
||||
printStack bool
|
||||
userError bool // If this is an error on the user side, which causes logging at a lower level.
|
||||
}
|
||||
|
||||
func (e smtpError) Error() string { return e.err.Error() }
|
||||
func (e smtpError) Unwrap() error { return e.err }
|
||||
|
||||
func xsmtpErrorf(code int, secode string, userError bool, format string, args ...any) {
|
||||
panic(smtpError{code, secode, fmt.Errorf(format, args...), false, userError})
|
||||
}
|
||||
|
||||
func xsmtpServerErrorf(codes codes, format string, args ...any) {
|
||||
xsmtpErrorf(codes.code, codes.secode, false, format, args...)
|
||||
}
|
||||
|
||||
func xsmtpUserErrorf(code int, secode string, format string, args ...any) {
|
||||
xsmtpErrorf(code, secode, true, format, args...)
|
||||
}
|
Reference in New Issue
Block a user