Skip to content

Commit

Permalink
add try catch
Browse files Browse the repository at this point in the history
  • Loading branch information
surmon-china committed Feb 28, 2019
1 parent 290b912 commit aff4192
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@

## CHANGELOG

### v0.1.2

增加容错处理

### v0.1.0

实现基本功能。
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wonderful-bing-wallpaper",
"version": "0.1.0",
"version": "0.1.2",
"description": "A simple bing daily wallpaper api lib",
"main": "dist/bing.js",
"bugs": {
Expand Down
8 changes: 7 additions & 1 deletion src/bing.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,13 @@ class WonderfulBingWallpaper {
}
let body = []
res.on('data', data => { body.push(data) })
res.on('end', () => resolve(JSON.parse(Buffer.concat(body).toString())))
res.on('end', () => {
try {
resolve(JSON.parse(Buffer.concat(body).toString()))
} catch (error) {
reject(error)
}
})
})
request.on('error', reject)
request.end()
Expand Down

0 comments on commit aff4192

Please sign in to comment.