Skip to content

Commit

Permalink
errors don't come back as json
Browse files Browse the repository at this point in the history
  • Loading branch information
dylang committed Apr 29, 2016
1 parent 135cdd3 commit a7f7f24
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
16 changes: 11 additions & 5 deletions index.js
Expand Up @@ -14,11 +14,11 @@ function whatDog(imageUrl) {
version: '001',
faceUrl: imageUrl,
faceName: imageUrl
},
json: true
}
}).then(response => {
try {
const whatDog = JSON.parse(response.body);
// Silly Microsoft double-JSON encoded their output?!
const whatDog = JSON.parse(JSON.parse(response.body));
return {
isDog: whatDog.IsDog,
breed: whatDog.BreedName,
Expand All @@ -28,11 +28,17 @@ function whatDog(imageUrl) {
return {
isDog: false,
breed: 'Not a dog',
about: ''
about: '',
err: err
};
}
}).catch(err => {
throw new Error(err);
return {
isDog: false,
breed: 'Not a dog',
about: '',
err: err
};
});
}

Expand Down
6 changes: 3 additions & 3 deletions test.js
Expand Up @@ -30,7 +30,7 @@ test('no url', async t => {
t.is(result3.message, 'A valid url is required.');
});

test('non-image url', async t => {
const result = await t.throws(whatdog('http://microsoft.com/'));
t.regex(result.message, /ParseError.*/);
test('non-dod url', async t => {
const result = await whatdog('http://microsoft.com/');
t.is(result.isDog, false);
});

0 comments on commit a7f7f24

Please sign in to comment.