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:
parent
542a7acfe6
commit
1d78a2705f
@ -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 }]) => {
|
||||
|
@ -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) {
|
||||
|
@ -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));
|
||||
|
@ -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();
|
||||
}
|
||||
}),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
Loading…
x
Reference in New Issue
Block a user