Skip to content

Commit

Permalink
fix: 🐛 display status & message error
Browse files Browse the repository at this point in the history
  • Loading branch information
touv committed Jul 2, 2020
1 parent c7ed6e4 commit 2f67590
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 10 deletions.
9 changes: 4 additions & 5 deletions packages/analytics/src/combine.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,13 @@ export default function combine(data, feed) {
append: this.getParam('append'),
});
const cache = this.getParam('cache');
let pipeline;
let statements;
if (cache) {
pipeline = ezs(cache, { commands });
statements = [ezs(cache, { commands }, this.getEnv())];
} else {
const statements = ezs.compileCommands(commands, this.getEnv());
pipeline = ezs.createPipeline(input, statements);
statements = ezs.compileCommands(commands, this.getEnv());
}
const output = pipeline
const output = ezs.createPipeline(input, statements)
.pipe(ezs.catch())
.on('data', async (item) => {
const key = get(item, 'id');
Expand Down
2 changes: 1 addition & 1 deletion packages/basics/src/url-connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function URLConnect(data, feed) {
})
.then((response) => {
if (response.status !== 200) {
const msg = `Received status code ${response.statusCode} (${response.statusMessage})'`;
const msg = `Received status code ${response.status} (${response.statusText})'`;
throw new Error(msg);
}
return response.body;
Expand Down
4 changes: 1 addition & 3 deletions packages/basics/src/url-fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ function URLFetch(data, feed) {
fetch(url)
.then((response) => {
if (response.status !== 200) {
const msg = `Received status code ${response.statusCode} (${
response.statusMessage
})'`;
const msg = `Received status code ${response.status} (${response.statusText})'`;
throw new Error(msg);
}
return json ? response.json() : response.text();
Expand Down
2 changes: 1 addition & 1 deletion packages/basics/src/url-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function URLStream(data, feed) {
fetch(cURL.href)
.then((response) => {
if (response.status !== 200) {
const msg = `Received status code ${response.statusCode} (${response.statusMessage})'`;
const msg = `Received status code ${response.status} (${response.statusText})'`;
throw new Error(msg);
}
return response.body;
Expand Down
16 changes: 16 additions & 0 deletions packages/basics/test/url-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,20 @@ describe('URLStream', () => {
done();
});
});
test('#2', (done) => {
const input = [1, 2, 3, 4, 5];
from(input)
.pipe(ezs('URLStream', {
url: 'https://httpbin.org/status/400',
}))
.pipe(ezs.catch())
.on('error', (e) => {
expect(e.message).toEqual(expect.stringContaining('400'));
done();
})
.on('end', () => {
done(new Error('Error is the right behavior'));
});
});

});

0 comments on commit 2f67590

Please sign in to comment.