Skip to content

Commit

Permalink
update npm modules, fix optional 404 problem (#341)
Browse files Browse the repository at this point in the history
* fix optional 404 problem for mtp

* update packages

* check for ERR_NODATA

Co-authored-by: Katie Dai <[email protected]>
  • Loading branch information
kdai7 and Katie Dai authored Sep 2, 2022
1 parent 7a280dc commit b1fb650
Show file tree
Hide file tree
Showing 3 changed files with 374 additions and 203 deletions.
15 changes: 9 additions & 6 deletions lib/FetchEnvs.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,11 @@ module.exports = class FetchEnvs {
const data = resource?.data;

if (!data) {
console.log(kubeError);
const msg = `failed to get envFrom: ${JSON.stringify(conf)}. ${kubeError.message || kubeError}`;
const err = new Error(msg);
err.code = objectPath.get(kubeError, 'error.code');
if (!optional) throw err;
err.code = kubeError.statusCode;
if (!optional || (err.code != 404 && kubeError != ERR_NODATA)) throw err;
log.warn(msg);
this.updateRazeeLogs('warn', { controller: 'FetchEnvs', message: msg });
return { ...conf, data };
Expand Down Expand Up @@ -140,7 +141,7 @@ module.exports = class FetchEnvs {
qs: matchLabelsQS
});
} catch (error) {
kubeError = error.message;
kubeError = error;
}
}

Expand All @@ -157,9 +158,11 @@ module.exports = class FetchEnvs {
}

if (value === undefined) {
if (defaultValue === undefined) {
const msg = `failed to get env: ${JSON.stringify(conf)}. ${kubeError}`;
if (!optional) throw new Error(msg);
if (defaultValue === undefined || (kubeError.statusCode != 404 && kubeError != ERR_NODATA)) {
const msg = `failed to get env: ${JSON.stringify(conf)}. ${kubeError.message || kubeError}`;
const err = new Error(msg);
err.code = kubeError.statusCode;
if (!optional || (err.code != 404 && kubeError != ERR_NODATA)) throw err;
log.warn(msg);
this.updateRazeeLogs('warn', { controller: 'FetchEnvs', message: msg });
} else {
Expand Down
Loading

0 comments on commit b1fb650

Please sign in to comment.