diff --git a/build.sh b/build.sh index 4ef1f98..dff3c2f 100644 --- a/build.sh +++ b/build.sh @@ -5,6 +5,7 @@ function BUNDLE { echo "Bundling..." rm -rf dist yarn bundle + rm -rf dist/__tests__ echo "Bundling done." } diff --git a/src/Request.ts b/src/Request.ts index 1d8b522..274b7e5 100644 --- a/src/Request.ts +++ b/src/Request.ts @@ -59,13 +59,20 @@ export default class Request { switch (response.status) { case 400: - message = 'Something went wrong 400'; + message = 'Something went wrong'; } - throw new Error(message); + throw new Error(`Dribbblejs - ${response.status}: ${message}`); } - private static parseResponse(response: Response) { - return response.json(); + private static async parseResponse(response: Response) { + const responseClone = response.clone(); + + try { + const data = await response.json(); + return data; + } catch (err) { + return await responseClone.text(); + } } }