-
Notifications
You must be signed in to change notification settings - Fork 579
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1688 from snyk/refactor/generate-test-error
refactor: generate snyk test error
- Loading branch information
Showing
2 changed files
with
30 additions
and
24 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
export function generateSnykTestError(error) { | ||
// Possible error cases: | ||
// - the test found some vulns. `error.message` is a | ||
// JSON-stringified | ||
// test result. | ||
// - the flow failed, `error` is a real Error object. | ||
// - the flow failed, `error` is a number or string | ||
// describing the problem. | ||
// | ||
// To standardise this, make sure we use the best _object_ to | ||
// describe the error. | ||
let errorResponse; | ||
if (error instanceof Error) { | ||
errorResponse = error; | ||
} else if (typeof error !== 'object') { | ||
errorResponse = new Error(error); | ||
} else { | ||
try { | ||
errorResponse = JSON.parse(error.message); | ||
} catch (unused) { | ||
errorResponse = error; | ||
} | ||
} | ||
return errorResponse; | ||
} |
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