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

Accessing error code from returned error #28

Closed
bendikro opened this issue Jul 24, 2017 · 2 comments · Fixed by #31
Closed

Accessing error code from returned error #28

bendikro opened this issue Jul 24, 2017 · 2 comments · Fixed by #31

Comments

@bendikro
Copy link
Contributor

When performing a CreateDatabase where the database already exists, the database returns error code 1207 (https://docs.arangodb.com/3.0/Manual/Appendix/ErrorCodes.html, ERROR_ARANGO_DUPLICATE_NAME).

This error code is wrapped in a numberedError at https://github.com/solher/arangolite/blob/v2.0.1/database.go#L207

However, at the next step, the numberedError is wrapped in a statusCodedError at https://github.com/solher/arangolite/blob/v2.0.1/database.go#L213

The statusCodedError is what is returned by Send.

My question is how should the error code be accessed?

HasErrorNum will not work, since it requires a numberedError as input, and casting to statusCodedError to access the error attribute doesn't work, since statusCodedError is not exported.

Current result of arangolite.HasStatusCode(err) is 409, but arangolite.HasErrorNum(e_status, 1207) gives false.

@solher
Copy link
Owner

solher commented Jul 24, 2017

Well the answer is quite simple. I just messed up my wrapping :)
Could you try again with the tip? It should be fixed now.
I also added some GetErrorNum and GetStatusCode functions to allow better debugging.

@bendikro
Copy link
Contributor Author

Hi @solher

Look at these tests: https://github.com/bendikro/arangolite/blob/master-error-tests/errors_test.go

Are they supposed to pass?

I still don't understand how I can access the error number when the numberedError is wrapped inside a statusCodedError.

bendikro added a commit to bendikro/arangolite that referenced this issue Jul 25, 2017
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 a pull request may close this issue.

2 participants