Procházet zdrojové kódy

[api] Improve error handling for non-decodable files in /display filebrowser API (#4130)

Instead of displaying raw binary content when file decoding fails, returns a user-friendly error message suggesting file download as an alternative.

Adds error logging to help diagnose encoding issues in server logs.
Harsh Gupta před 7 měsíci
rodič
revize
2c6299e67f
1 změnil soubory, kde provedl 2 přidání a 1 odebrání
  1. 2 1
      apps/filebrowser/src/filebrowser/api.py

+ 2 - 1
apps/filebrowser/src/filebrowser/api.py

@@ -410,7 +410,8 @@ def display(request):
       file_contents = contents.decode(encoding)
       mode = 'text'
     except UnicodeDecodeError:
-      file_contents = contents
+      LOG.error("Cannot decode file contents with encoding: %s." % encoding)
+      return HttpResponse("Cannot display file content. Please download the file instead.", status=422)
 
   data = {
     'contents': file_contents,