-
Notifications
You must be signed in to change notification settings - Fork 532
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
1 parent
351c7bd
commit b202896
Showing
2 changed files
with
87 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import * as errors from '../../../../../src/lib/errors/legacy-errors'; | ||
import { FormattedCustomError } from '../../../../../src/lib/errors'; | ||
|
||
describe('errors.message', () => { | ||
it('returns the error message if it is a VULNS error', () => { | ||
const errorMessage = 'This is an error message'; | ||
const error = new Error(errorMessage) as any; | ||
(error as any).code = 'VULNS'; | ||
|
||
const result = errors.message(error); | ||
|
||
expect(result).toBe(errorMessage); | ||
}); | ||
|
||
it('returns the error message if there is a message and it is a FormattedCustomError', () => { | ||
const formattedUserMessage = 'This is a formatted user error message'; | ||
const error = new FormattedCustomError( | ||
'This is an error message', | ||
formattedUserMessage, | ||
); | ||
|
||
const result = errors.message(error); | ||
|
||
expect(result).toBe(error.formattedUserMessage); | ||
}); | ||
|
||
it('returns the error message based on the error code', () => { | ||
const error = new Error('Unauthorized') as any; | ||
error.code = 'Unauthorized'; | ||
|
||
const result: string = errors.message(error); | ||
|
||
// comparing with toContain because the error message is formatted to be red and bold | ||
expect(result).toContain( | ||
'Unauthorized: please ensure you are logged in using `snyk auth`', | ||
); | ||
}); | ||
|
||
it('returns the error message based on the error message (404)', () => { | ||
const error = new Error('404'); | ||
|
||
const result: string = errors.message(error); | ||
|
||
// comparing with toContain because the error message is formatted to be red and bold | ||
expect(result).toContain( | ||
'The package could not be found or does not exist', | ||
); | ||
}); | ||
|
||
it('returns the error message based on the error message (NOT_FOUND)', () => { | ||
const error = new Error('NOT_FOUND'); | ||
|
||
const result: string = errors.message(error); | ||
|
||
// comparing with toContain because the error message is formatted to be red and bold | ||
expect(result).toContain( | ||
'The package could not be found or does not exist', | ||
); | ||
}); | ||
|
||
it('returns unknown error message for unknowne error code', () => { | ||
const error = new Error('Bad request') as any; | ||
error.code = 400; | ||
|
||
const result = errors.message(error); | ||
|
||
expect(result).toBe( | ||
'An unknown error occurred. Please run with `-d` and include full trace when reporting to Snyk', | ||
); | ||
}); | ||
|
||
it('returns the error message if it is not recognized', () => { | ||
const error = new Error('This is an unknown error'); | ||
|
||
const result = errors.message(error); | ||
|
||
expect(result).toBe<string>(error.message); | ||
}); | ||
|
||
it('returns the error message if it is a string', () => { | ||
const errorMessage = 'This is an error message'; | ||
|
||
const result = errors.message(errorMessage); | ||
|
||
expect(result).toBe(errorMessage); | ||
}); | ||
}); |