Skip to content

Commit b1fb650

Browse files
kdai7Katie Dai
andauthored
update npm modules, fix optional 404 problem (#341)
* fix optional 404 problem for mtp * update packages * check for ERR_NODATA Co-authored-by: Katie Dai <kdai7@ibm.com>
1 parent 7a280dc commit b1fb650

File tree

3 files changed

+374
-203
lines changed

3 files changed

+374
-203
lines changed

lib/FetchEnvs.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,11 @@ module.exports = class FetchEnvs {
8989
const data = resource?.data;
9090

9191
if (!data) {
92+
console.log(kubeError);
9293
const msg = `failed to get envFrom: ${JSON.stringify(conf)}. ${kubeError.message || kubeError}`;
9394
const err = new Error(msg);
94-
err.code = objectPath.get(kubeError, 'error.code');
95-
if (!optional) throw err;
95+
err.code = kubeError.statusCode;
96+
if (!optional || (err.code != 404 && kubeError != ERR_NODATA)) throw err;
9697
log.warn(msg);
9798
this.updateRazeeLogs('warn', { controller: 'FetchEnvs', message: msg });
9899
return { ...conf, data };
@@ -140,7 +141,7 @@ module.exports = class FetchEnvs {
140141
qs: matchLabelsQS
141142
});
142143
} catch (error) {
143-
kubeError = error.message;
144+
kubeError = error;
144145
}
145146
}
146147

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

159160
if (value === undefined) {
160-
if (defaultValue === undefined) {
161-
const msg = `failed to get env: ${JSON.stringify(conf)}. ${kubeError}`;
162-
if (!optional) throw new Error(msg);
161+
if (defaultValue === undefined || (kubeError.statusCode != 404 && kubeError != ERR_NODATA)) {
162+
const msg = `failed to get env: ${JSON.stringify(conf)}. ${kubeError.message || kubeError}`;
163+
const err = new Error(msg);
164+
err.code = kubeError.statusCode;
165+
if (!optional || (err.code != 404 && kubeError != ERR_NODATA)) throw err;
163166
log.warn(msg);
164167
this.updateRazeeLogs('warn', { controller: 'FetchEnvs', message: msg });
165168
} else {

0 commit comments

Comments
 (0)