Skip to content

Commit

Permalink
fix: auth error should be 4xx, not 500
Browse files Browse the repository at this point in the history
traceback:
```
  File "/code/nmdc_runtime/api/models/user.py", line 59, in get_current_user
    payload = jwt.decode(token, SECRET_KEY, algorithms=[ALGORITHM])
  File "/usr/local/lib/python3.10/site-packages/jose/jwt.py", line 142, in decode
    payload = jws.verify(token, key, algorithms, verify=verify_signature)
  File "/usr/local/lib/python3.10/site-packages/jose/jws.py", line 70, in verify
    header, payload, signing_input, signature = _load(token)
  File "/usr/local/lib/python3.10/site-packages/jose/jws.py", line 176, in _load
    signing_input, crypto_segment = jwt.rsplit(b".", 1)
AttributeError: 'NoneType' object has no attribute 'rsplit'
```
  • Loading branch information
dwinston committed Feb 20, 2024
1 parent 85ebb1e commit 7d0dad9
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion nmdc_runtime/api/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ async def get_current_user(
raise credentials_exception
username = subject.split("user:", 1)[1]
token_data = TokenData(subject=username)
except JWTError as e:
except (JWTError, AttributeError) as e:
print(f"jwt error: {e}")
raise credentials_exception
user = get_user(mdb, username=token_data.subject)
Expand Down

0 comments on commit 7d0dad9

Please sign in to comment.