data layer
This commit is contained in:
33
data-layer/workers/internal/apperr/apperr.go
Normal file
33
data-layer/workers/internal/apperr/apperr.go
Normal file
@@ -0,0 +1,33 @@
|
||||
// Package apperr defines AppError, the single error type used across the
|
||||
// worker. Job handlers wrap any underlying driver error before returning so
|
||||
// river retry/log lines stay consistent with the api service.
|
||||
package apperr
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type AppError struct {
|
||||
Message string
|
||||
Err error
|
||||
}
|
||||
|
||||
func (e *AppError) Error() string {
|
||||
if e.Err != nil {
|
||||
return fmt.Sprintf("%s: %v", e.Message, e.Err)
|
||||
}
|
||||
return e.Message
|
||||
}
|
||||
|
||||
func (e *AppError) Unwrap() error { return e.Err }
|
||||
|
||||
func As(err error) (*AppError, bool) {
|
||||
var ae *AppError
|
||||
if errors.As(err, &ae) {
|
||||
return ae, true
|
||||
}
|
||||
return nil, false
|
||||
}
|
||||
|
||||
func Wrap(msg string, err error) *AppError { return &AppError{Message: msg, Err: err} }
|
||||
Reference in New Issue
Block a user