Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to customize errors response structure. #1321

Merged
merged 1 commit into from Aug 3, 2017
Merged

Add ability to customize errors response structure. #1321

merged 1 commit into from Aug 3, 2017

Conversation

brycereitano
Copy link
Contributor

@brycereitano brycereitano commented Jul 27, 2017

This provides the interface for merging custom error response structs.

Tests and documentation to come after review of approach.

@brycereitano brycereitano changed the title Initial mergable error commit. Add ability to customize errors response structure. Jul 27, 2017
Copy link
Member

@raphael raphael left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks for doing this! I left a few nitpicks in the review.

error.go Outdated
@@ -265,6 +299,14 @@ func (e *ErrorResponse) Token() string { return e.ID }
// Merge returns the updated error. This is useful in case the error was initially nil in
// which case other is returned.
func MergeErrors(err, other error) error {
// If either err is mergable, merge them.

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

error.go Outdated
}
return e
}

// MergeErrors updates an error by merging another into it. It first converts other into a

This comment was marked as off-topic.

error.go Outdated
// ServiceMergeableError extends from the ServiceError interface.
ServiceError

// Merge will handle the logic of merging two errors together.

This comment was marked as off-topic.

@brycereitano
Copy link
Contributor Author

@raphael Updated so that ErrorResponse doesn't implement ServiceMergableError. As it can cause the old merging logic to be called if err happens to a goa.ErrorResponse.

error.go Outdated
@@ -254,6 +264,8 @@ func (e *ErrorResponse) Token() string { return e.ID }
// ServiceError if not already one - producing an internal error in that case. The merge algorithm
// is:
//
// * If any of e or other implements ServiceMergableError, it is handled by it's Merge method.

This comment was marked as off-topic.

This comment was marked as off-topic.

@brycereitano
Copy link
Contributor Author

Once this is merged, this should close #1173.

Copy link
Member

@raphael raphael left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for doing this, looks great! I left a couple of comments in the code review.

@@ -300,24 +310,22 @@ var _ = Describe("Merge", func() {
})
})

Context("with a nil argument", func() {
const code = "foo"
Context("with a nil target", func() {

This comment was marked as off-topic.

This comment was marked as off-topic.

error_test.go Outdated
})
})

Context("with MergableError", func() {

This comment was marked as off-topic.

@raphael raphael merged commit 4f4b96b into goadesign:v1 Aug 3, 2017
@raphael
Copy link
Member

raphael commented Aug 3, 2017

Looks great - thank you! Do you think you could also send a PR against master? thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants