Skip to content

Commit

Permalink
refactor: rework response parser
Browse files Browse the repository at this point in the history
  • Loading branch information
animify committed Feb 22, 2020
1 parent 30863ce commit b256d17
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
1 change: 1 addition & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ function BUNDLE {
echo "Bundling..."
rm -rf dist
yarn bundle
rm -rf dist/__tests__
echo "Bundling done."
}

Expand Down
15 changes: 11 additions & 4 deletions src/Request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}

0 comments on commit b256d17

Please sign in to comment.