github.com/prebid/prebid-server/v2@v2.18.0/hooks/hookexecution/errors.go (about) 1 package hookexecution 2 3 import ( 4 "fmt" 5 6 "github.com/prebid/prebid-server/v2/errortypes" 7 ) 8 9 // TimeoutError indicates exceeding of the max execution time allotted for hook. 10 type TimeoutError struct{} 11 12 func (e TimeoutError) Error() string { 13 return "Hook execution timeout" 14 } 15 16 func NewFailure(format string, a ...any) FailureError { 17 return FailureError{Message: fmt.Sprintf(format, a...)} 18 } 19 20 // FailureError indicates expected error occurred during hook execution on the module-side. 21 // A moduleFailed metric will be sent in such case. 22 type FailureError struct { 23 Message string 24 } 25 26 func (e FailureError) Error() string { 27 return fmt.Sprintf("hook execution failed: %s", e.Message) 28 } 29 30 // RejectError indicates stage rejection requested by specific hook. 31 // Implements errortypes.Coder interface for compatibility only, 32 // so as not to be recognized as a fatal error 33 type RejectError struct { 34 NBR int 35 Hook HookID 36 Stage string 37 } 38 39 func (e RejectError) Code() int { 40 return errortypes.ModuleRejectionErrorCode 41 } 42 43 func (e RejectError) Severity() errortypes.Severity { 44 return errortypes.SeverityWarning 45 } 46 47 func (e RejectError) Error() string { 48 return fmt.Sprintf( 49 `Module %s (hook: %s) rejected request with code %d at %s stage`, 50 e.Hook.ModuleCode, 51 e.Hook.HookImplCode, 52 e.NBR, 53 e.Stage, 54 ) 55 } 56 57 func FindFirstRejectOrNil(errors []error) *RejectError { 58 for _, err := range errors { 59 if rejectErr, ok := CastRejectErr(err); ok { 60 return rejectErr 61 } 62 } 63 return nil 64 } 65 66 func CastRejectErr(err error) (*RejectError, bool) { 67 rejectErr, ok := err.(*RejectError) 68 return rejectErr, ok 69 }