Skip to content

Wrapping original issue in rest.Error #269

@Dragomir-Ivanov

Description

@Dragomir-Ivanov

There is an rest.Error type that captures all unrecognized errors from Hooks:

	if err = rsrc.Update(ctx, item, original); err != nil {
		e = NewError(err)
		return e.Code, nil, e
	}

func NewError(err error) *Error {
switch err {
...
default:
		return &Error{520, err.Error(), nil}
	}
}

However sometimes, enriched errors are used(preserving call-trace), that become useless once stringed through err.Error(). Can we preseve original error like this:

// Error defines a REST error with optional per fields error details.
type Error struct {
	// Code defines the error code to be used for the error and for the HTTP
	// status.
	Code int
	// Message is the error message.
	Message string
	// Issues holds per fields errors if any.
	Issues map[string][]interface{}
	Err    error // Or even Errs []error
}

So I can use the errors in func (r ResponseFormatter) FormatError( and send them to say Sentry or logs.

This might be a breaking change if someone is not following go vet recommendations(like in rest-layer source code :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions