Skip to content

Commit

Permalink
Handling exception of invalid header and strip token (#825)
Browse files Browse the repository at this point in the history
  • Loading branch information
Raalsky authored Jan 20, 2022
1 parent 151b332 commit ff3d394
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## [UNRELEASED] neptune-client 0.14.3

## Features
- Stripping whitespaces from Neptune API Token ([#825](https://github.com/neptune-ai/neptune-client/pull/825))

## Fixes
- Raise proper exception when invalid token were provided ([#825](https://github.com/neptune-ai/neptune-client/pull/825))

## neptune-client 0.14.2

### Features
Expand Down
5 changes: 5 additions & 0 deletions neptune/new/internal/backends/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
ClientHttpError,
NeptuneFeatureNotAvailableException,
MetadataInconsistency,
NeptuneInvalidApiTokenException,
)
from neptune.new.internal.backends.api_model import ClientConfig
from neptune.new.internal.operation import Operation, CopyAttribute
Expand Down Expand Up @@ -99,6 +100,10 @@ def wrapper(*args, **kwargs):

try:
return func(*args, **kwargs)
except requests.exceptions.InvalidHeader as e:
if "X-Neptune-Api-Token" in e.args[0]:
raise NeptuneInvalidApiTokenException()
raise
except requests.exceptions.SSLError as e:
raise SSLError() from e
except (
Expand Down
1 change: 1 addition & 0 deletions neptune/new/internal/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def from_token(cls, api_token: Optional[str] = None) -> "Credentials":
if api_token is None:
raise NeptuneMissingApiTokenException()

api_token = api_token.strip()
token_dict = Credentials._api_token_to_dict(api_token)
# TODO: Consider renaming 'api_address' (breaking backward compatibility)
if "api_address" not in token_dict:
Expand Down

0 comments on commit ff3d394

Please sign in to comment.