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

Smarter acceptable error #13

Open
junhuif opened this issue Jan 14, 2017 · 1 comment
Open

Smarter acceptable error #13

junhuif opened this issue Jan 14, 2017 · 1 comment
Assignees

Comments

@junhuif
Copy link
Member

junhuif commented Jan 14, 2017

We need to accept multiple types of errors when posting a resource.

@junhuif junhuif self-assigned this Jan 14, 2017
@junhuif
Copy link
Member Author

junhuif commented Jan 14, 2017

type acceptable interface{
	Acceptable() bool
}

// isAcceptable will be compared against the behaviour of errors
// from `db.Create`. If the behaviour match, Post will respond with
// HTTPStatusUnprocessableEntity instead of panicking.
func isAcceptable(err error) bool {
	ae, ok := errors.Cause(err).(acceptable)
	return ok && ae.Acceptable()
}

Em... Checking behaviour makes things worse. The origin requirement is that there is two type of validation error types that returned by db.Create.

junhuif added a commit that referenced this issue Jan 14, 2017
junhuif added a commit that referenced this issue Jan 14, 2017
There is two type of validation error that returned by `db.Create`.
This change support detect multiple type of errors.

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

No branches or pull requests

1 participant