Error with ErrorCode (useful for HTTP Errors)

This commit is contained in:
Jürgen Edelbluth 2023-10-09 19:19:37 +02:00
parent a3f6c03851
commit ef7d25655c
Signed by: jed
GPG Key ID: 6DEAEDD5CDB646DF

View File

@ -3,9 +3,12 @@ package stacktrace
import ( import (
"fmt" "fmt"
"git.codebau.dev/goblins/commons/pkg/osdep" "git.codebau.dev/goblins/commons/pkg/osdep"
"math"
"runtime" "runtime"
) )
const NoStatusCode = math.MinInt
type ErrorReporter struct { type ErrorReporter struct {
EnableStacktraces bool EnableStacktraces bool
} }
@ -18,7 +21,8 @@ type StackElement struct {
type ErrorWithStacktrace struct { type ErrorWithStacktrace struct {
error error
Stack *[]*StackElement ErrorCode int
Stack *[]*StackElement
} }
func (s *ErrorWithStacktrace) build(enableStackTraces bool) { func (s *ErrorWithStacktrace) build(enableStackTraces bool) {
@ -65,7 +69,13 @@ func (s *ErrorWithStacktrace) Stacktrace() *[]*StackElement {
} }
func (r *ErrorReporter) New(err error) *ErrorWithStacktrace { func (r *ErrorReporter) New(err error) *ErrorWithStacktrace {
s := &ErrorWithStacktrace{error: err} s := &ErrorWithStacktrace{error: err, ErrorCode: NoStatusCode}
s.build(r.EnableStacktraces)
return s
}
func (r *ErrorReporter) NewWithErrorCode(errorCode int, err error) *ErrorWithStacktrace {
s := &ErrorWithStacktrace{error: err, ErrorCode: errorCode}
s.build(r.EnableStacktraces) s.build(r.EnableStacktraces)
return s return s
} }