improvement: use clear error if Git Gateway off (#1695)
This commit is contained in:
parent
2c6eed81dd
commit
62b2f9c06b
@ -1,7 +1,7 @@
|
|||||||
import GoTrue from 'gotrue-js';
|
import GoTrue from 'gotrue-js';
|
||||||
import jwtDecode from 'jwt-decode';
|
import jwtDecode from 'jwt-decode';
|
||||||
import { get, pick, intersection } from 'lodash';
|
import { get, pick, intersection } from 'lodash';
|
||||||
import { unsentRequest } from 'netlify-cms-lib-util';
|
import { APIError, unsentRequest } from 'netlify-cms-lib-util';
|
||||||
import { GitHubBackend } from 'netlify-cms-backend-github';
|
import { GitHubBackend } from 'netlify-cms-backend-github';
|
||||||
import { GitLabBackend } from 'netlify-cms-backend-gitlab';
|
import { GitLabBackend } from 'netlify-cms-backend-gitlab';
|
||||||
import { BitBucketBackend, API as BitBucketAPI } from 'netlify-cms-backend-bitbucket';
|
import { BitBucketBackend, API as BitBucketAPI } from 'netlify-cms-backend-bitbucket';
|
||||||
@ -90,7 +90,28 @@ export default class GitGateway {
|
|||||||
{
|
{
|
||||||
headers: { Authorization: `Bearer ${token}` },
|
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;
|
this.acceptRoles = roles;
|
||||||
if (github_enabled) {
|
if (github_enabled) {
|
||||||
this.backendType = 'github';
|
this.backendType = 'github';
|
||||||
|
Loading…
x
Reference in New Issue
Block a user