Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悰 Fixed HTTP 500 error when image processing fails during upload #19842

Merged
merged 1 commit into from Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion ghost/core/core/server/api/endpoints/images.js
Expand Up @@ -33,7 +33,12 @@ module.exports = {
width: config.get('imageOptimization:defaultMaxWidth')
}, imageOptimizationOptions);

await imageTransform.resizeFromPath(options);
try {
await imageTransform.resizeFromPath(options);
} catch (err) {
// If the image processing fails, we just want to store the original image
return store.save(frame.file);
}

// Store the processed/optimized image
const processedImageUrl = await store.save({
Expand Down
10 changes: 10 additions & 0 deletions ghost/core/test/e2e-api/admin/images.test.js
Expand Up @@ -301,4 +301,14 @@ describe('Images API', function () {
await uploadImageCheck({path: originalFilePath, filename: 'a.png', contentType: 'image/png'});
clock.restore();
});

it('Does not return HTTP 500 when image processing fails', async function () {
sinon.stub(imageTransform, 'resizeFromPath').rejects(new Error('Image processing failed'));

const originalFilePath = p.join(__dirname, '/../../utils/fixtures/images/ghost-logo.png');
const fileContents = await fs.readFile(originalFilePath);

await uploadImageRequest({fileContents, filename: 'test.png', contentType: 'image/png'})
.expectStatus(201);
});
});