Skip to content

fix(platform/api): catch JSONDecodeError in courses view to return 400 instead of 500 #647

Description

@payamnj

Problem

All json.loads(request.body) calls in platform/api/views/courses.py are unguarded. A malformed request body raises json.JSONDecodeError which bubbles up as a 500 response instead of a clean 400.

Affected methods:

  • CourseView.post
  • CourseContentView.post
  • ReorderCourseContentView.post
  • SingleCourseContentView.post
  • SingleCourseView.post
  • SendLessonToPlatformUser.post

Suggestion

Add a shared parse_body helper that catches json.JSONDecodeError and returns a consistent 400 error payload, then use it in all the above methods.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status
    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions