Explorar el Código

[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 hace 10 meses
padre
commit
2c6299e67f
Se han modificado 1 ficheros con 2 adiciones y 1 borrados
  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,