canvasapi icon indicating copy to clipboard operation
canvasapi copied to clipboard

Error messages contain nested dictionaries

Open jessemcbride opened this issue 3 years ago • 0 comments

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:

  1. Try to enroll in a concluded course
  2. Receive a BadRequest exception and catch as e
  3. 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.

jessemcbride avatar Apr 27 '21 17:04 jessemcbride