Skip to content

Commit

Permalink
feat(fixture): Add throw behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
liqueurdetoile committed Jun 22, 2019
1 parent 5ebb704 commit f8e238e
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/Fixture.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,12 @@ export class Fixture extends ResponseConfigurator {
return this;
}

throw(message = '') {
this.before(function () {
throw new FMFException(message);
});
}

async match(request, server) {
/* istanbul ignore if */
if (!this._matcher) return true;
Expand Down Expand Up @@ -268,7 +274,7 @@ export class Fixture extends ResponseConfigurator {

if (responseReplacement) response = responseReplacement;
} catch (err) {
return this._exceptionManagement(err, 'Unable to process before callback');
return this._exceptionManagement(err, err.message || 'Unable to process before callback');
}
}

Expand All @@ -283,7 +289,7 @@ export class Fixture extends ResponseConfigurator {
server: this.server
}) : response.body;
} catch (err) {
return this._exceptionManagement(err, 'Unable to process body callback');
return this._exceptionManagement(err, err.message || 'Unable to process body callback');
}

// Apply preset
Expand All @@ -304,7 +310,7 @@ export class Fixture extends ResponseConfigurator {
try {
if (response.after instanceof Function) await response.after.call(this, this.server, responseObject);
} catch (err) {
return this._exceptionManagement(err, 'Unable to process after callback');
return this._exceptionManagement(err, err.message || 'Unable to process after callback');
}

// Delay response
Expand Down

0 comments on commit f8e238e

Please sign in to comment.