1
0
mirror of https://github.com/kataras/iris.git synced 2026-01-09 13:05:56 +00:00

omit errors received by the server via configuration 🍪 | requested by https://github.com/kataras/iris/issues/668

relative link: https://github.com/kataras/iris/issues/668


Former-commit-id: 6491abd68b74e18bf4ed0b32406e67597c9b55a9
This commit is contained in:
hiveminded
2017-07-13 16:31:36 +03:00
parent ace439203d
commit 16ccb2edc4
12 changed files with 294 additions and 64 deletions

View File

@@ -37,6 +37,16 @@ func New(errMsg string) Error {
}
}
// NewFromErr same as `New` but pointer for nil checks without the need of the `Return()` function.
func NewFromErr(err error) *Error {
if err == nil {
return nil
}
errp := New(err.Error())
return &errp
}
// Equal returns true if "e" and "e2" are matched, by their IDs.
// It will always returns true if the "e2" is a children of "e"
// or the error messages are exactly the same, otherwise false.
@@ -123,6 +133,17 @@ func (e Error) With(err error) error {
return e.Format(err.Error())
}
// Ignore will ignore the "err" and return nil.
func (e Error) Ignore(err error) error {
if err == nil {
return e
}
if e.Error() == err.Error() {
return nil
}
return e
}
// Panic output the message and after panics.
func (e Error) Panic() {
_, fn, line, _ := runtime.Caller(1)

View File

@@ -106,12 +106,12 @@ func (r *Reporter) Describe(format string, err error) {
// PrintStack prints all the errors to the given "printer".
// Returns itself in order to be used as printer and return the full error in the same time.
func (r Reporter) PrintStack(printer func(string, ...interface{})) error {
func (r *Reporter) PrintStack(printer func(string, ...interface{})) error {
return PrintAndReturnErrors(r, printer)
}
// Stack returns the list of the errors in the stack.
func (r Reporter) Stack() []Error {
func (r *Reporter) Stack() []Error {
return r.wrapper.Stack
}
@@ -127,12 +127,12 @@ func (r *Reporter) addStack(stack []Error) {
}
// Error implements the error, returns the full error string.
func (r Reporter) Error() string {
func (r *Reporter) Error() string {
return r.wrapper.Error()
}
// Return returns nil if the error is empty, otherwise returns the full error.
func (r Reporter) Return() error {
func (r *Reporter) Return() error {
if r.Error() == "" {
return nil
}