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

Provide compete Atlas api response in exceptions #36

Closed
p-mongo opened this issue Apr 20, 2020 · 3 comments · Fixed by #49
Closed

Provide compete Atlas api response in exceptions #36

p-mongo opened this issue Apr 20, 2020 · 3 comments · Fixed by #49

Comments

@p-mongo
Copy link
Contributor

p-mongo commented Apr 20, 2020

I am currently getting the following error from astrolabe:

atlasclient.exceptions.AtlasApiError: 404: Not Found. Error Code: 'NOT_ATLAS_GROUP' (GET https://cloud.mongodb.com/api/atlas/v1.0/groups/byName/x)

If I inspect the response returned by the api, I see this:

(Pdb) response.content
b'{"detail":"Group 5e9d09c5e373b17421f92ca2 is not an Atlas group; use the Cloud Manager Public API at /api/public/v1.0 to access it.","error":404,"errorCode":"NOT_ATLAS_GROUP","parameters":["5e9d09c5e373b17421f92ca2"],"reason":"Not Found"}'

As a user of Astrolabe I would like Astrolabe to include all information that api returns into its exceptions so that I can effectively troubleshooting errors.

@prashantmital
Copy link
Contributor

Instead of always including the full response by default, I have added the ability to see this output at an elevated logging level. I have also added a brief documentation note on how to use logging levels: https://mongodb-labs.github.io/drivers-atlas-testing/installing-running-locally.html#debugging

Just use the 'debug' logging level and you will see the full request and response. For example:

$ astrolabe --log-level DEBUG projects get-one --group-name x1
DEBUG:astrolabe.cli:Atlas Client Configuration:
======================  ===================================
Configuration option    Value
======================  ===================================
Atlas API base URL      https://cloud.mongodb.com/api/atlas
HTTP timeout (s)        10.0
======================  ===================================
DEBUG:atlasclient.client:Request (GET https://cloud.mongodb.com/api/atlas/v1.0/groups/byName/x1 {'auth': <requests.auth.HTTPDigestAuth object at 0x106caffd0>, 'params': {}, 'json': {}, 'timeout': 10.0})
DEBUG:atlasclient.client:Response (GET {'detail': 'The current user is not in the group, or the group does not exist.', 'error': 401, 'errorCode': 'NOT_IN_GROUP', 'parameters': [], 'reason': 'Unauthorized'})
Traceback (most recent call last):
  File "/Users/pmital/.pyenv/versions/3.7.5/envs/atlastesting/bin/astrolabe", line 11, in <module>
    load_entry_point('astrolabe', 'console_scripts', 'astrolabe')()
  File "/Users/pmital/.pyenv/versions/3.7.5/envs/atlastesting/lib/python3.7/site-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/Users/pmital/.pyenv/versions/3.7.5/envs/atlastesting/lib/python3.7/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/Users/pmital/.pyenv/versions/3.7.5/envs/atlastesting/lib/python3.7/site-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Users/pmital/.pyenv/versions/3.7.5/envs/atlastesting/lib/python3.7/site-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Users/pmital/.pyenv/versions/3.7.5/envs/atlastesting/lib/python3.7/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/pmital/.pyenv/versions/3.7.5/envs/atlastesting/lib/python3.7/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/Users/pmital/.pyenv/versions/3.7.5/envs/atlastesting/lib/python3.7/site-packages/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/Users/pmital/Developer/drivers-atlas-testing/astrolabe/cli.py", line 204, in get_one_project_by_name
    pprint(ctx.obj.groups.byName[group_name].get().data)
  File "/Users/pmital/Developer/drivers-atlas-testing/atlasclient/client.py", line 56, in get
    return self._client.request('GET', self._path, **params)
  File "/Users/pmital/Developer/drivers-atlas-testing/atlasclient/client.py", line 221, in request
    return self.handle_response(method, response)
  File "/Users/pmital/Developer/drivers-atlas-testing/atlasclient/client.py", line 258, in handle_response
    raise AtlasAuthenticationError('401: Unauthorized.', **kwargs)
atlasclient.exceptions.AtlasAuthenticationError: 401: Unauthorized. Error Code: 'NOT_IN_GROUP' (GET https://cloud.mongodb.com/api/atlas/v1.0/groups/byName/x1)

@p-mongo
Copy link
Contributor Author

p-mongo commented Apr 24, 2020

The complete response is not provided. Example: https://gist.github.com/p-mongo/6711c5f08e2926b3cd4ab825876e828b

I have a patch as follows that I am using:

carbon% git diff
diff --git a/atlasclient/client.py b/atlasclient/client.py
index d0d8a09..01a9d6a 100644
--- a/atlasclient/client.py
+++ b/atlasclient/client.py
@@ -257,5 +257,6 @@ class AtlasClient:
         if response.status_code == 409:
             raise AtlasApiError('409: Conflict.', **kwargs)
 
+        print(response.content)
         raise AtlasApiError('{}: Unknown.'.format(response.status_code),
                             **kwargs)

This patch produces the following line in the linked gist:

b'{"detail":"Unexpected error.","error":500,"errorCode":"UNEXPECTED_ERROR","parameters":[],"reason":"Internal Server Error"}'

The remainder of the gist (which is output produced by unpatched astrolabe) does not include the "reason":"Internal Server Error" part.

@p-mongo p-mongo reopened this Apr 24, 2020
@p-mongo
Copy link
Contributor Author

p-mongo commented Apr 24, 2020

Works correctly after I updated my tree.

@p-mongo p-mongo closed this as completed Apr 24, 2020
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