From a38fb909b7801a44802328d511e5dcf28b2d004f Mon Sep 17 00:00:00 2001 From: star-nox Date: Mon, 2 Oct 2023 12:33:50 -0500 Subject: [PATCH] removed json import and added abort to canvas functions --- ai_ta_backend/main.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/ai_ta_backend/main.py b/ai_ta_backend/main.py index bfc3fcca..f5ecbe31 100644 --- a/ai_ta_backend/main.py +++ b/ai_ta_backend/main.py @@ -2,7 +2,6 @@ import os import time from typing import List -import json from dotenv import load_dotenv from flask import Flask, Response, abort, jsonify, request @@ -401,6 +400,15 @@ def ingest_canvas(): canvas = CanvasAPI() canvas_course_id: str = request.args.get('course_id') course_name: str = request.args.get('course_name') + + if canvas_course_id == '' or course_name == '': + # proper web error "400 Bad request" + abort( + 400, + description= + f"Missing one or more required parameters: 'course_id' and 'course_name' must be provided. course_id: `{canvas_course_id}`, course_name: `{course_name}`" + ) + success_or_failure = canvas.ingest_course_content(canvas_course_id, course_name) response = jsonify({"outcome": success_or_failure}) response.headers.add('Access-Control-Allow-Origin', '*') @@ -414,6 +422,15 @@ def update_canvas(): canvas = CanvasAPI() canvas_course_id: str = request.args.get('course_id') course_name: str = request.args.get('course_name') + + if canvas_course_id == '' or course_name == '': + # proper web error "400 Bad request" + abort( + 400, + description= + f"Missing one or more required parameters: 'course_id' and 'course_name' must be provided. course_id: `{canvas_course_id}`, course_name: `{course_name}`" + ) + success_or_failure = canvas.update_course_content(canvas_course_id, course_name) response = jsonify({"outcome": success_or_failure}) response.headers.add('Access-Control-Allow-Origin', '*')