소스 검색

[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 7 달 전
부모
커밋
2c6299e67f
1개의 변경된 파일2개의 추가작업 그리고 1개의 파일을 삭제
  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,