Skip to content

Commit

Permalink
v11.0.6 handle 4xx errors gracefully
Browse files Browse the repository at this point in the history
  • Loading branch information
iamruinous committed Jul 31, 2017
1 parent 1462281 commit f297eb2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 21 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "meshblu-connector-factory-ui",
"version": "11.0.5",
"version": "11.0.6",
"description": "meshblu-connector-factory-ui",
"main": "index.js",
"scripts": {
Expand Down
43 changes: 23 additions & 20 deletions src/services/fetch-json-service.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
import request from 'superagent'

export function getJSON({ uri }, callback) {
request.get(uri)
.end((error, response) => {
if (error) {
callback(error)
request.get(uri).end((error, response) => {
if (error) {
callback(error)
return
}
if (response.clientError) {
callback(null, {})
return
}
if (!response.ok) {
callback(new Error('Invalid Response'))
return
}
const { body, text } = response
let jsonResponse = body
if (!body && text) {
try {
jsonResponse = JSON.parse(text)
} catch (error) {
callback(new Error('Unable to Parse JSON'))
return
}
if (!response.ok) {
callback(new Error('Invalid Response'))
return
}
const { body, text } = response
let jsonResponse = body
if (!body && text) {
try {
jsonResponse = JSON.parse(text)
} catch (error) {
callback(new Error('Unable to Parse JSON'))
return
}
}
callback(null, jsonResponse)
})
}
callback(null, jsonResponse)
})
}

0 comments on commit f297eb2

Please sign in to comment.