From 22448c098bb7c86cf59c5f9fcc1bd4b2cbb09ec8 Mon Sep 17 00:00:00 2001 From: jomo Date: Sun, 5 Apr 2020 02:42:14 +0200 Subject: [PATCH] use 500 instead of 502 when using Cloudflare Otherwise Cloudflare will replace images served with 502 with their own error page. This can only be turned off in paid plans of Cloudflare. --- lib/response.js | 8 +++++++- lib/views/index.html.ejs | 7 ++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/response.js b/lib/response.js index 7f63d99..da6e95b 100644 --- a/lib/response.js +++ b/lib/response.js @@ -95,7 +95,13 @@ module.exports = function(request, response, result) { if (result.err && result.err.code === "ENOENT") { result.code = result.code || 500; } - response.writeHead(result.code || 502, headers); + if (!result.code) { + // Don't use 502 on Cloudflare + // As they will show their own error page instead + // https://support.cloudflare.com/hc/en-us/articles/200172706 + result.code = config.caching.cloudflare ? 500 : 502; + } + response.writeHead(result.code, headers); } else { if (result.body) { if (result.status === 4) { diff --git a/lib/views/index.html.ejs b/lib/views/index.html.ejs index 4439fcb..b43dd93 100644 --- a/lib/views/index.html.ejs +++ b/lib/views/index.html.ejs @@ -227,7 +227,12 @@

HTTP Headers

- Crafatar always replies with a 200 OK status code when the requested user's skin/cape was found. This is also used in some rare cases when Mojang servers are having issues and the image couldn't be checked for changes, but Crafatar still had a cached version. 502 Bad Gateway and 500 Server Error are used when no skin/cape was found because of Mojang or Crafatar server issues. + Crafatar always replies with a 200 OK status code when the requested user's skin/cape was found. This is also used in some rare cases when Mojang servers are having issues and the image couldn't be checked for changes, but Crafatar still had a cached version. + <% if (config.caching.cloudflare) { %> + 500 Server Error is used when no skin/cape was found because of Mojang or Crafatar server issues. + <% } else { %> + 502 Bad Gateway and 500 Server Error are used when no skin/cape was found because of Mojang or Crafatar server issues. + <% } %>

Note that requests are usually answered with an image (with Steve/Alex skin), even if an error occured!