Skip to content

Commit b202896

Browse files
authored
fix: do not show invalidSeverityThreshold error for HTTP 400 responses (#4920)
* fix: do not show invalidSeverityThreshold error for HTTP 400 responses fixes SUP-2006 * test: add tests for legacy-errors
1 parent 351c7bd commit b202896

File tree

2 files changed

+87
-1
lines changed

2 files changed

+87
-1
lines changed

src/lib/errors/legacy-errors.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ const codes = {
5353
411: errors.endpoint, // try to post to a weird endpoint
5454
403: errors.endpoint,
5555
401: errors.auth,
56-
400: errors.invalidSeverityThreshold,
5756
Unauthorized: errors.auth,
5857
MISSING_NODE_MODULES: errors.nodeModules,
5958
OLD_DOTFILE_FORMAT: errors.oldsnyk,
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import * as errors from '../../../../../src/lib/errors/legacy-errors';
2+
import { FormattedCustomError } from '../../../../../src/lib/errors';
3+
4+
describe('errors.message', () => {
5+
it('returns the error message if it is a VULNS error', () => {
6+
const errorMessage = 'This is an error message';
7+
const error = new Error(errorMessage) as any;
8+
(error as any).code = 'VULNS';
9+
10+
const result = errors.message(error);
11+
12+
expect(result).toBe(errorMessage);
13+
});
14+
15+
it('returns the error message if there is a message and it is a FormattedCustomError', () => {
16+
const formattedUserMessage = 'This is a formatted user error message';
17+
const error = new FormattedCustomError(
18+
'This is an error message',
19+
formattedUserMessage,
20+
);
21+
22+
const result = errors.message(error);
23+
24+
expect(result).toBe(error.formattedUserMessage);
25+
});
26+
27+
it('returns the error message based on the error code', () => {
28+
const error = new Error('Unauthorized') as any;
29+
error.code = 'Unauthorized';
30+
31+
const result: string = errors.message(error);
32+
33+
// comparing with toContain because the error message is formatted to be red and bold
34+
expect(result).toContain(
35+
'Unauthorized: please ensure you are logged in using `snyk auth`',
36+
);
37+
});
38+
39+
it('returns the error message based on the error message (404)', () => {
40+
const error = new Error('404');
41+
42+
const result: string = errors.message(error);
43+
44+
// comparing with toContain because the error message is formatted to be red and bold
45+
expect(result).toContain(
46+
'The package could not be found or does not exist',
47+
);
48+
});
49+
50+
it('returns the error message based on the error message (NOT_FOUND)', () => {
51+
const error = new Error('NOT_FOUND');
52+
53+
const result: string = errors.message(error);
54+
55+
// comparing with toContain because the error message is formatted to be red and bold
56+
expect(result).toContain(
57+
'The package could not be found or does not exist',
58+
);
59+
});
60+
61+
it('returns unknown error message for unknowne error code', () => {
62+
const error = new Error('Bad request') as any;
63+
error.code = 400;
64+
65+
const result = errors.message(error);
66+
67+
expect(result).toBe(
68+
'An unknown error occurred. Please run with `-d` and include full trace when reporting to Snyk',
69+
);
70+
});
71+
72+
it('returns the error message if it is not recognized', () => {
73+
const error = new Error('This is an unknown error');
74+
75+
const result = errors.message(error);
76+
77+
expect(result).toBe<string>(error.message);
78+
});
79+
80+
it('returns the error message if it is a string', () => {
81+
const errorMessage = 'This is an error message';
82+
83+
const result = errors.message(errorMessage);
84+
85+
expect(result).toBe(errorMessage);
86+
});
87+
});

0 commit comments

Comments
 (0)