Skip to content

Commit

Permalink
fix: Avoid throwing an exception if needle can't connect to the mock …
Browse files Browse the repository at this point in the history
…service during polling (may fix #314)
  • Loading branch information
TimothyJones committed Aug 11, 2021
1 parent 76f6db1 commit 74a2cde
Showing 1 changed file with 20 additions and 22 deletions.
42 changes: 20 additions & 22 deletions src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,30 +311,28 @@ export abstract class AbstractService extends events.EventEmitter {
}

private __call(options: ServiceOptions): Promise<unknown> {
return new Promise<void>((resolve, reject) => {
const config: HTTPConfig = {
method: 'GET',
headers: {
'X-Pact-Mock-Service': 'true',
'Content-Type': 'application/json',
},
};
const config: HTTPConfig = {
method: 'GET',
headers: {
'X-Pact-Mock-Service': 'true',
'Content-Type': 'application/json',
},
};

if (options.ssl) {
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
config.rejectUnauthorized = false;
config.agent = false;
}
if (options.ssl) {
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
config.rejectUnauthorized = false;
config.agent = false;
}

needle.get(
`http${options.ssl ? 's' : ''}://${options.host}:${options.port}`,
config,
(err: Error | null, res) => {
!err && res.statusCode === 200
? resolve()
: reject(`HTTP Error: '${JSON.stringify(err ? err : res)}'`);
}
);
return needle(
'get',
`http${options.ssl ? 's' : ''}://${options.host}:${options.port}`,
config
).then((res) => {
if (res.statusCode !== 200) {
throw new Error(`HTTP Error: '${JSON.stringify(res)}'`);
}
});
}
}
Expand Down

0 comments on commit 74a2cde

Please sign in to comment.