canvasapi
canvasapi copied to clipboard
Error messages contain nested dictionaries
Describe the bug
canvasapi stores error messages in a message
key on CanvasException
types to provide users with more information about what went wrong during a request. It seems like these messages aren't parsed correctly before being attached to the exception object, requiring downstream users of the library to parse the error messages themselves.
To Reproduce
Steps to reproduce the behavior:
- Try to enroll in a concluded course
- Receive a
BadRequest
exception and catch ase
- Observe that
e.message
is a stringified JSON object:
print(vars(e))
{'message': '{"message":"Can\'t add an enrollment to a concluded course."}'}
Expected behavior
It seems more intuitive that canvasapi would parse the error message from JSON and then store it as a string, i.e. e.message = "Can't add an enrollment to a concluded course."
.
Environment information
- Python version (
python --version
): Python 3.7.9 - CanvasAPI version (
pip show canvasapi
): canvasapi==2.0.0
Additional context
This likely occurs with other exceptions as well.