Error with ErrorCode (useful for HTTP Errors)
This commit is contained in:
parent
a3f6c03851
commit
ef7d25655c
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user