diff --git a/src/api/img.ts b/src/api/img.ts index 42bb7156..400ee1df 100755 --- a/src/api/img.ts +++ b/src/api/img.ts @@ -35,7 +35,7 @@ export default ({ config, db }) => } else { await imageAction.prossesImage() - if (config.imageable.caching.active) { + if (config.imageable.caching.active && !imageAction.error) { cache.image = imageAction.imageBuffer await cache.save() } diff --git a/src/image/action/local/index.ts b/src/image/action/local/index.ts index 82114eaf..ea40385e 100644 --- a/src/image/action/local/index.ts +++ b/src/image/action/local/index.ts @@ -6,6 +6,7 @@ export default class LocalImageAction extends ImageAction { public imageOptions public SUPPORTED_MIMETYPES = ['image/gif', 'image/png', 'image/jpeg', 'image/webp', 'image/svg+xml'] public imageBuffer: Buffer + public error = false public get whitelistDomain (): string[] { return this.options.imageable.whitelist @@ -90,10 +91,18 @@ export default class LocalImageAction extends ImageAction { try { this.imageBuffer = await downloadImage(imgUrl) } catch (err) { - return this.res.status(400).send({ - code: 400, - result: `Unable to download the requested image ${imgUrl}` - }) + this.error = true + if (err.statusCode === 404) { + return this.res.status(404).send({ + code: 404, + result: 'Not found' + }) + } else { + return this.res.status(500).send({ + code: 500, + result: `Unable to download the requested image ${imgUrl}` + }) + } } const { action, width, height } = this.imageOptions switch (action) {