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 (
"fmt"
"git.codebau.dev/goblins/commons/pkg/osdep"
"math"
"runtime"
)
const NoStatusCode = math.MinInt
type ErrorReporter struct {
EnableStacktraces bool
}
@ -18,6 +21,7 @@ type StackElement struct {
type ErrorWithStacktrace struct {
error
ErrorCode int
Stack *[]*StackElement
}
@ -65,7 +69,13 @@ func (s *ErrorWithStacktrace) Stacktrace() *[]*StackElement {
}
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)
return s
}