From 424a49e36c92501bad9610fbbe646088d7ab5400 Mon Sep 17 00:00:00 2001 From: Caleb Date: Wed, 29 Aug 2018 19:44:01 -0600 Subject: [PATCH] improvement: clear error if Git Gateway settings 404 --- .../src/implementation.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/netlify-cms-backend-git-gateway/src/implementation.js b/packages/netlify-cms-backend-git-gateway/src/implementation.js index b41073c7..2d186871 100644 --- a/packages/netlify-cms-backend-git-gateway/src/implementation.js +++ b/packages/netlify-cms-backend-git-gateway/src/implementation.js @@ -90,7 +90,20 @@ export default class GitGateway { { headers: { Authorization: `Bearer ${token}` }, }, - ).then(res => res.json()); + ).then(async res => { + const contentType = res.headers.get('Content-Type'); + if (contentType !== 'application/json' && contentType !== 'text/json') { + throw new APIError(`Your Git Gateway backend is not returning valid settings. Please make sure it is enabled.`, res.status, 'Git Gateway'); + } + + const body = await res.json(); + + if (!res.ok) { + throw new APIError(`Git Gateway Error: ${(body.message ? body.message : body)}`, res.status, 'Git Gateway'); + } + + return body; + }); this.acceptRoles = roles; if (github_enabled) { this.backendType = 'github';