Skip to content
This repository has been archived by the owner on Oct 10, 2022. It is now read-only.

Commit

Permalink
Tweak json parsing error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
bcomnes committed Sep 14, 2018
1 parent d7fd319 commit de37da9
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions src/open-api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const queryString = require('qs')
const fetch = require('node-fetch')
const Headers = fetch.Headers
const camelCase = require('lodash.camelcase')
const { JSONHTTPError, TextHTTPError, HTTPError } = require('micro-api-client')
const { JSONHTTPError, TextHTTPError } = require('micro-api-client')

function existy(val) {
return val != null
Expand Down Expand Up @@ -85,12 +85,7 @@ exports.generateMethod = method => {
const contentType = response.headers.get('Content-Type')

if (contentType && contentType.match(/json/)) {
let json
try {
json = await response.json()
} catch (e) {
throw new JSONHTTPError(response, json)
}
const json = await response.json()
if (!response.ok) {
throw new JSONHTTPError(response, json)
}
Expand Down

0 comments on commit de37da9

Please sign in to comment.