From 824d6de4487add0e16a20f785a715f6e22f69f94 Mon Sep 17 00:00:00 2001 From: Marcin Mielnicki <marcin.mielnicki@gmail.com> Date: Sun, 27 Oct 2019 18:35:14 +0100 Subject: [PATCH] Redirect to a static badge instead of returning status code 500 --- core/base-service/redirector.js | 3 ++- core/base-service/redirector.spec.js | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/core/base-service/redirector.js b/core/base-service/redirector.js index 40b412b9af..e0803f635f 100644 --- a/core/base-service/redirector.js +++ b/core/base-service/redirector.js @@ -122,7 +122,8 @@ module.exports = function redirector(attrs) { ask.res.setHeader('Location', redirectUrl) } catch (e) { log.error(new Error(`An invalid URL in '${this.name}' redirector.`)) - ask.res.statusCode = 500 + ask.res.statusCode = 302 + ask.res.setHeader('Location', '/badge/badge-inaccessible-lightgray') } // To avoid caching mistakes for a long time, and to make this simpler // to reason about, use the same cache semantics as the static badge. diff --git a/core/base-service/redirector.spec.js b/core/base-service/redirector.spec.js index 18c4d92547..79c9a63ef2 100644 --- a/core/base-service/redirector.spec.js +++ b/core/base-service/redirector.spec.js @@ -94,16 +94,16 @@ describe('Redirector', function() { }) // https://github.com/badges/shields/issues/4013 - it('should return status code 500 when redirect URL is invalid (contains invalid characters)', async function() { + it('should temporarily redirect to a badge with message "inaccesible" when cunstructed redirect URL is invalid (contains invalid characters)', async function() { const { statusCode, headers } = await got( `${baseUrl}/very/old/service/hello\nworld.svg`, { - throwHttpErrors: false, + followRedirect: false, } ) - expect(statusCode).to.equal(500) - expect(headers.location).to.be.undefined + expect(statusCode).to.equal(302) + expect(headers.location).to.equal('/badge/badge-inaccessible-lightgray') }) it('should redirect raster extensions to the canonical path as configured', async function() { -- GitLab