Skip to content

Commit

Permalink
refactor: create custom error class
Browse files Browse the repository at this point in the history
  • Loading branch information
InesNi committed Nov 23, 2023
1 parent ce620dc commit 3700de4
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions packages/artillery-plugin-expect/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ function expectationsPluginOnError(
events,
done
) {
if (scenarioErr.message.startsWith('Failed expectations for request')) {
if (scenarioErr instanceof FailedExpectationError) {
return done();
}
if (userContext.expectationsPlugin.formatter === 'json') {
Expand Down Expand Up @@ -186,7 +186,9 @@ function expectationsPluginCheckExpectations(
? req.name
: req.url;
return done(
new Error(`Failed expectations for request ${filteredRequestName}`)
new FailedExpectationError(
`Failed expectations for request ${filteredRequestName}`
)
);
}

Expand All @@ -213,3 +215,10 @@ function maybeParseBody(res) {
return res.body;
}
}

class FailedExpectationError extends Error {
constructor(message) {
super(message);
this.name = 'FailedExpectationError';
}
}

0 comments on commit 3700de4

Please sign in to comment.