Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(adapter): Log information if request couldn't be found in recording #172

Merged
merged 1 commit into from
Jan 31, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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