From 9d6c98fc66d47993ccbb64321e1fbdc0441999c8 Mon Sep 17 00:00:00 2001 From: Marcos Prieto Date: Mon, 4 Nov 2024 18:08:46 +0100 Subject: [PATCH] Add extra logging for Moodle's file check We are seeing a school response that doesn't seem to contain the content type header we rely on to determine if a file still exists in Moodle. Before we try alternative approaches to detect if a file exists lets add some logging to check the response headers. One possible explanation could be that we are dealing with two different issues issues: - The server doesn't return the content type header for this request Maybe a different Moodle version? Some server configured in front of Moodle strips them. - The file doesn't exist on the server or we can access it for some reason. --- lms/services/moodle.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lms/services/moodle.py b/lms/services/moodle.py index 4a66061f6d..7cfad7fe52 100644 --- a/lms/services/moodle.py +++ b/lms/services/moodle.py @@ -4,6 +4,9 @@ from lms.services.aes import AESService from lms.services.exceptions import ExternalRequestError from lms.services.http import HTTPService +import logging + +LOG = logging.getLogger(__name__) class Function(StrEnum): @@ -139,6 +142,8 @@ def file_exists(self, file_id) -> bool: # We don't want to download the full file so we'll do a HEAD request and assume: # - JSON response, it's an error response # - Anything else, it's the file we are after + + LOG.info("Headers from Moodle file check %s", response.headers) return not response.headers["content-type"].startswith("application/json") def page(self, course_id, page_id) -> dict | None: