Consistently log internal errors
This commit is contained in:
parent
13c5529a41
commit
b9cf98eee8
3 changed files with 16 additions and 10 deletions
|
|
@ -2,6 +2,8 @@ package report
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
type ErrorWithCode struct {
|
||||
|
|
@ -17,6 +19,10 @@ func (e *ErrorWithCode) Error() string {
|
|||
return e.message
|
||||
}
|
||||
|
||||
func newInternalError(err error, format string, args ...any) *ErrorWithCode {
|
||||
log.Error().Err(err).Str("format", format).Msg("internal server error")
|
||||
return newErrorWithCode("internal-error", format, args...)
|
||||
}
|
||||
func newErrorWithCode(code string, format string, args ...any) *ErrorWithCode {
|
||||
if len(args) > 0 {
|
||||
return &ErrorWithCode{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue