Skip to content

Commit

Permalink
Improve API error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
mclintprojects committed Aug 18, 2024
1 parent 5c51a0c commit 99cb117
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,15 @@ class Cashramp {
},
});

const json = await response.json();
if (json.errors) {
return { success: false, error: json.errors[0].message };
if (response.status == 200) {
const json = await response.json();
if (json.errors) {
return { success: false, error: json.errors[0].message };
} else {
return { success: true, result: json.data[name] };
}
} else {
return { success: true, result: json.data[name] };
return { success: false, error: response.statusText };
}
} catch (err) {
console.log(err);
Expand Down

0 comments on commit 99cb117

Please sign in to comment.