improvement: add logs when a 404 error is expected (#2807)

improvement: add logs when a 404 error is expected

improvement: address code review feedback -return rejected promise
This commit is contained in:
ed ho 2019-11-10 00:34:03 -08:00 committed by Erez Rokah
parent 542a7acfe6
commit 1d78a2705f
4 changed files with 32 additions and 4 deletions

View File

@ -256,7 +256,14 @@ export default class GitGateway {
.readFile('.gitattributes')
.then(getLargeMediaPatternsFromGitAttributesFile)
.then(patterns => ({ patterns }))
.catch(err => (err.message.includes('404') ? [] : { err }));
.catch(err => {
if (err.message.includes('404')) {
console.log('This 404 was expected and handled appropriately.');
return [];
} else {
return { err };
}
});
return Promise.all([netlifyLargeMediaEnabledPromise, lfsPatternsPromise]).then(
([{ enabled: maybeEnabled }, { patterns, err: patternsErr }]) => {

View File

@ -14,7 +14,14 @@ import {
const CMS_BRANCH_PREFIX = 'cms';
const replace404WithEmptyArray = err => (err && err.status === 404 ? [] : Promise.reject(err));
const replace404WithEmptyArray = err => {
if (err && err.status === 404) {
console.log('This 404 was expected and handled appropriately.');
return [];
} else {
return Promise.reject(err);
}
};
export default class API {
constructor(config) {

View File

@ -107,7 +107,14 @@ export default class GitHub {
headers: { Authorization: `token ${token}` },
})
.then(() => true)
.catch(err => (err && err.status === 404 ? false : Promise.reject(err)));
.catch(err => {
if (err && err.status === 404) {
console.log('This 404 was expected and handled appropriately.');
return false;
} else {
return Promise.reject(err);
}
});
// wait between polls
if (!repoExists) {
await new Promise(resolve => setTimeout(resolve, pollDelay));

View File

@ -148,7 +148,14 @@ export function loadMedia(opts = {}) {
.catch(
error =>
console.error(error) ||
dispatch(error.status === 404 ? mediaLoaded() : mediaLoadFailed()),
dispatch(() => {
if (error.status === 404) {
console.log('This 404 was expected and handled appropriately.');
return mediaLoaded();
} else {
return mediaLoadFailed();
}
}),
),
),
);