Skip to content

Commit

Permalink
fix(adapter): Log information if request couldn't be found in recording
Browse files Browse the repository at this point in the history
These three fields are referenced in the _identify function.

Fixes #114
  • Loading branch information
Dustin Masters authored and dustinsoftware committed Jan 30, 2019
1 parent 9db417a commit 6f7ffc2
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions packages/@pollyjs/adapter/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,15 @@ export default class Adapter {
async [REQUEST_HANDLER](pollyRequest) {
const { mode } = this.polly;
let interceptor;

if (pollyRequest.shouldIntercept) {
const {
shouldIntercept,
shouldPassthrough,
identifiers,
id,
order
} = pollyRequest;

if (shouldIntercept) {
interceptor = new Interceptor();
const response = await this.intercept(pollyRequest, interceptor);

Expand All @@ -123,7 +130,7 @@ export default class Adapter {

if (
mode === MODES.PASSTHROUGH ||
pollyRequest.shouldPassthrough ||
shouldPassthrough ||
(interceptor && interceptor.shouldPassthrough)
) {
return this.passthrough(pollyRequest);
Expand All @@ -144,7 +151,8 @@ export default class Adapter {

// This should never be reached. If it did, then something screwy happened.
this.assert(
`Unhandled request: ${pollyRequest.method} ${pollyRequest.url}.`,
'Unhandled request: \n' +
JSON.stringify({ identifiers, id, order }, null, 2),
false
);
}
Expand All @@ -171,7 +179,7 @@ export default class Adapter {
}

async replay(pollyRequest) {
const { config } = pollyRequest;
const { config, identifiers, id, order } = pollyRequest;
const recordingEntry = await this.persister.findEntry(pollyRequest);

if (recordingEntry) {
Expand Down Expand Up @@ -205,7 +213,8 @@ export default class Adapter {

this.assert(
'Recording for the following request is not found and `recordIfMissing` is `false`.\n' +
`${pollyRequest.method} ${pollyRequest.url}\n`,
JSON.stringify({ identifiers, id, order }, null, 2) +
'\n',
false
);
}
Expand Down

0 comments on commit 6f7ffc2

Please sign in to comment.