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.
The url field is included just in case it is not included already in
the identifiers.
  • Loading branch information
Dustin Masters authored and dustinsoftware committed Jan 31, 2019
1 parent 9db417a commit 9f3d519
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions packages/@pollyjs/adapter/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,16 @@ export default class Adapter {
async [REQUEST_HANDLER](pollyRequest) {
const { mode } = this.polly;
let interceptor;

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

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

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

if (
mode === MODES.PASSTHROUGH ||
pollyRequest.shouldPassthrough ||
shouldPassthrough ||
(interceptor && interceptor.shouldPassthrough)
) {
return this.passthrough(pollyRequest);
Expand All @@ -144,7 +152,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, url }, null, 2),
false
);
}
Expand All @@ -171,7 +180,7 @@ export default class Adapter {
}

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

if (recordingEntry) {
Expand Down Expand Up @@ -205,7 +214,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, url }, null, 2) +
'\n',
false
);
}
Expand Down

0 comments on commit 9f3d519

Please sign in to comment.