Skip to content

Commit

Permalink
Upgrade xo to 0.23.0
Browse files Browse the repository at this point in the history
  • Loading branch information
lukechilds committed Jan 14, 2019
1 parent c1543b0 commit 9a72e67
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 18 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"pify": "^4.0.0",
"sqlite3": "^4.0.2",
"this": "^1.0.2",
"xo": "^0.22.0"
"xo": "^0.23.0"
},
"xo": {
"extends": "xo-lukechilds"
Expand Down
32 changes: 17 additions & 15 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class CacheableRequest {
'';
url = normalizeUrlObject({ ...opts, pathname, search });
}

opts = {
headers: {},
method: 'GET',
Expand Down Expand Up @@ -128,16 +129,16 @@ class CacheableRequest {
}

await this.cache.set(key, value, ttl);
} catch (err) {
ee.emit('error', new CacheableRequest.CacheError(err));
} catch (error) {
ee.emit('error', new CacheableRequest.CacheError(error));
}
})();
} else if (opts.cache && revalidate) {
(async () => {
try {
await this.cache.delete(key);
} catch (err) {
ee.emit('error', new CacheableRequest.CacheError(err));
} catch (error) {
ee.emit('error', new CacheableRequest.CacheError(error));
}
})();
}
Expand All @@ -153,8 +154,8 @@ class CacheableRequest {
req.once('error', requestErrorCallback);
req.once('abort', requestErrorCallback);
ee.emit('request', req);
} catch (err) {
ee.emit('error', new CacheableRequest.RequestError(err));
} catch (error) {
ee.emit('error', new CacheableRequest.RequestError(error));
}
};

Expand Down Expand Up @@ -185,15 +186,16 @@ class CacheableRequest {
}
};

this.cache.on('error', err => ee.emit('error', new CacheableRequest.CacheError(err)));
this.cache.on('error', error => ee.emit('error', new CacheableRequest.CacheError(error)));

try {
await get(opts);
} catch (err) {
} catch (error) {
if (opts.automaticFailover && !madeRequest) {
makeRequest(opts);
}
ee.emit('error', new CacheableRequest.CacheError(err));

ee.emit('error', new CacheableRequest.CacheError(error));
}
})();

Expand Down Expand Up @@ -229,18 +231,18 @@ function normalizeUrlObject(url) {
}

CacheableRequest.RequestError = class extends Error {
constructor(err) {
super(err.message);
constructor(error) {
super(error.message);
this.name = 'RequestError';
Object.assign(this, err);
Object.assign(this, error);
}
};

CacheableRequest.CacheError = class extends Error {
constructor(err) {
super(err.message);
constructor(error) {
super(error.message);
this.name = 'CacheError';
Object.assign(this, err);
Object.assign(this, error);
}
};

Expand Down
4 changes: 3 additions & 1 deletion test/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ async function testCacheKey(t, input, expected) {
okMessage
);
}

testCacheKey.title = (providedTitle, input) => util.format(
'Cache key is http.request compatible for arg %s(%j)%s',
input.constructor.name,
Expand Down Expand Up @@ -299,6 +300,7 @@ test('request options path query is passed through', async t => {
port: urlObject.port,
path: urlObject.path
};

const inputs = [argString, argURL, argOptions];
for (const input of inputs) {
// eslint-disable-next-line no-await-in-loop
Expand Down Expand Up @@ -553,7 +555,7 @@ test('Keyv cache adapters load via connection uri', async t => {
t.true(secondResponse.fromCache);
t.is(cacheResult.length, 1);

await query(`DELETE FROM keyv`);
await query('DELETE FROM keyv');
});

test('ability to force refresh', async t => {
Expand Down
2 changes: 1 addition & 1 deletion test/cacheable-request-instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ test.cb('cacheableRequest emits response event for cached responses', t => {
});

test.cb('cacheableRequest emits CacheError if cache adapter connection errors', t => {
const cacheableRequest = new CacheableRequest(request, `sqlite://non/existent/database.sqlite`);
const cacheableRequest = new CacheableRequest(request, 'sqlite://non/existent/database.sqlite');
cacheableRequest(url.parse(s.url))
.on('error', err => {
t.true(err instanceof CacheableRequest.CacheError);
Expand Down

0 comments on commit 9a72e67

Please sign in to comment.