Skip to content

Commit 9f2bffb

Browse files
committed
Improves error handling for non-decodable files
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.
1 parent a614768 commit 9f2bffb

File tree

1 file changed

+2
-1
lines changed
  • apps/filebrowser/src/filebrowser

1 file changed

+2
-1
lines changed

apps/filebrowser/src/filebrowser/api.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,8 @@ def display(request):
410410
file_contents = contents.decode(encoding)
411411
mode = 'text'
412412
except UnicodeDecodeError:
413-
file_contents = contents
413+
LOG.error("Cannot decode file contents with encoding: %s." % encoding)
414+
return HttpResponse("Cannot display file content. Please download the file instead.", status=422)
414415

415416
data = {
416417
'contents': file_contents,

0 commit comments

Comments
 (0)