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 response code to errors #21

Open
philipithomas opened this issue Feb 23, 2018 · 0 comments
Open

Add response code to errors #21

philipithomas opened this issue Feb 23, 2018 · 0 comments

Comments

@philipithomas
Copy link
Contributor

Debugging clearbit errors in our code has become a nightmare. This is what it looks like in our logs:

ERROR: clearbit:

Manually debugging, I've realized that this is because the API is returning codes like 404 or 422.

Internally, we end up wrapping the errors with github.com/pkg/errors and having to return different types of errors:

	res, resp, err := s.ClearbitClient.Person.FindCombined(clearbit.PersonFindParams{
		Email: r.Email,
	})

	if resp.StatusCode == 202 {
		// Deferred
		return r, errTryAgainLater
	} else if resp.StatusCode == 404 {
		return r, errEmailNotFound
	} else if resp.StatusCode == 422 {
		return r, errInvalid
	} else if err != nil {
		return r, errors.Wrap(err, fmt.Sprintf("code %d", r.StatusCode))
	}

I propose that this package either (1) has named error types that it returns (e.g. ErrNotFound), or that it at least wraps all errs with the API response status code.

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

No branches or pull requests

1 participant