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