You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 26, 2024. It is now read-only.
Provide more info why we don't have any thumbnails to serve (#13038)
Fix#13016
## New error code and status
### Before
Previously, we returned a `404` for `/thumbnail` which isn't even in the spec.
```json
{
"errcode": "M_NOT_FOUND",
"error": "Not found [b'hs1', b'tefQeZhmVxoiBfuFQUKRzJxc']"
}
```
### After
What does the spec say?
> 400: The request does not make sense to the server, or the server cannot thumbnail the content. For example, the client requested non-integer dimensions or asked for negatively-sized images.
>
> *-- https://spec.matrix.org/v1.1/client-server-api/#get_matrixmediav3thumbnailservernamemediaid*
Now with this PR, we respond with a `400` when we don't have thumbnails to serve and we explain why we might not have any thumbnails.
```json
{
"errcode": "M_UNKNOWN",
"error": "Cannot find any thumbnails for the requested media ([b'example.com', b'12345']). This might mean the media is not a supported_media_format=(image/jpeg, image/jpg, image/webp, image/gif, image/png) or that thumbnailing failed for some other reason. (Dynamic thumbnails are disabled on this server.)",
}
```
> Cannot find any thumbnails for the requested media ([b'example.com', b'12345']). This might mean the media is not a supported_media_format=(image/jpeg, image/jpg, image/webp, image/gif, image/png) or that thumbnailing failed for some other reason. (Dynamic thumbnails are disabled on this server.)
---
We still respond with a 404 in many other places. But we can iterate on those later and maybe keep some in some specific places after spec updates/clarification: matrix-org/matrix-spec#1122
We can also iterate on the bugs where Synapse doesn't thumbnail when it should in other issues/PRs.
# 1. We can't create thumbnails for the given media (corrupted or
404
+
# unsupported file type), or
405
+
# 2. The thumbnailing process never ran or errored out initially
406
+
# when the media was first uploaded (these bugs should be
407
+
# reported and fixed).
408
+
# Note that we don't attempt to generate a thumbnail now because
409
+
# `dynamic_thumbnails` is disabled.
387
410
logger.info("Failed to find any generated thumbnails")
388
-
respond_404(request)
411
+
412
+
respond_with_json(
413
+
request,
414
+
400,
415
+
cs_error(
416
+
"Cannot find any thumbnails for the requested media (%r). This might mean the media is not a supported_media_format=(%s) or that thumbnailing failed for some other reason. (Dynamic thumbnails are disabled on this server.)"
"""Test the given thumbnailing method works as expected.
497
+
498
+
Args:
499
+
method: The thumbnailing method to use (crop, scale).
500
+
expected_body: The expected bytes from thumbnailing, or None if
501
+
test should just check for a valid image.
502
+
expected_found: True if the file should exist on the server, or False if
503
+
a 404/400 is expected.
504
+
unable_to_thumbnail: True if we expect the thumbnailing to fail (400), or
505
+
False if the thumbnailing should succeed or a normal 404 is expected.
506
+
"""
507
+
464
508
params="?width=32&height=32&method="+method
465
509
channel=make_request(
466
510
self.reactor,
@@ -496,6 +540,16 @@ def _test_thumbnail(
496
540
else:
497
541
# ensure that the result is at least some valid image
498
542
Image.open(BytesIO(channel.result["body"]))
543
+
elifunable_to_thumbnail:
544
+
# A 400 with a JSON body.
545
+
self.assertEqual(channel.code, 400)
546
+
self.assertEqual(
547
+
channel.json_body,
548
+
{
549
+
"errcode": "M_UNKNOWN",
550
+
"error": "Cannot find any thumbnails for the requested media ([b'example.com', b'12345']). This might mean the media is not a supported_media_format=(image/jpeg, image/jpg, image/webp, image/gif, image/png) or that thumbnailing failed for some other reason. (Dynamic thumbnails are disabled on this server.)",
0 commit comments