Skip to content

Commit b366f3e

Browse files
authored
Merge pull request snyk#180 from snyk/feat/improve-system-check-error-messages
feat: improve systemcheck 401 error messages
2 parents cdba12d + 12306b6 commit b366f3e

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

lib/client/index.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ module.exports = ({ port = null, config = {}, filters = {} }) => {
4141
});
4242

4343
app.get(config.brokerSystemcheckPath || '/systemcheck', (req, res) => {
44-
// Systemcheck is the broker client's ability to assert the network
44+
// Systemcheck is the broker client's ability to assert the network
4545
// reachability and some correctness of credentials for the service
4646
// being proxied by the broker client.
4747

@@ -89,20 +89,26 @@ module.exports = ({ port = null, config = {}, filters = {} }) => {
8989
return res.status(500).json(data);
9090
}
9191

92-
data.brokerClientValidationUrlStatusCode = response && response.statusCode;
92+
const responseStatusCode = response && response.statusCode;
93+
data.brokerClientValidationUrlStatusCode = responseStatusCode;
94+
9395
// check for 2xx status code
94-
const goodStatusCode = /^2/.test(response && response.statusCode);
96+
const goodStatusCode = /^2/.test(responseStatusCode);
9597
if (!goodStatusCode) {
9698
data.ok = false;
97-
data.error = 'Status code is not 2xx';
99+
data.error = (responseStatusCode === 401 || responseStatusCode === 403)
100+
? 'Failed due to invalid credentials'
101+
: 'Status code is not 2xx';
102+
103+
logger.error(data, response && response.body, 'Systemcheck failed');
98104
return res.status(500).json(data);
99105
}
100106

101107
data.ok = true;
102108
return res.status(200).json(data);
103109
});
104110
});
105-
111+
106112
// relay all other URL paths
107113
app.all('/*', (req, res, next) => {
108114
res.locals.io = io;

0 commit comments

Comments
 (0)