diff --git a/core/base-service/redirector.js b/core/base-service/redirector.js index 40b412b9af5ce4fd77a3ee98070b8d64c7408354..e0803f635fcb27f9f618006354edf557ad61f84a 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 18c4d9254756104c66b394ede2042629a88d2484..79c9a63ef215160feee5a458d806e411c4be78d5 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() {