Skip to content

Commit

Permalink
Merge pull request #62 from bernardarhia/charge-reponse-correction
Browse files Browse the repository at this point in the history
Charge reponse correction
  • Loading branch information
bernardarhia authored Apr 6, 2024
2 parents 9f769d6 + 8f1409e commit 6383eff
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/many-trainers-joke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"paystackly": patch
---

proper error handling
17 changes: 13 additions & 4 deletions src/core/Http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,19 @@ class HttpClient {
);
return response.data;
} catch (error: any) {
return error.response.data;
return this.processErrorResponse(error);
}
}

private processErrorResponse(error: any) {
if(!error) return null;
if(error && error.response && error.response?.data) {
return error.response.data

}
throw new Error("There was an error processing your request")
}

public async post<RequestBody, Response>(
url: string,
data?: RequestBody,
Expand All @@ -45,7 +54,7 @@ class HttpClient {
);
return response.data;
} catch (error: any) {
return error.response.data;
return this.processErrorResponse(error);
}
}

Expand All @@ -62,7 +71,7 @@ class HttpClient {
);
return response.data;
} catch (error: any) {
return error.response.data;
return this.processErrorResponse(error);
}
}

Expand All @@ -79,7 +88,7 @@ class HttpClient {
);
return response.data;
} catch (error: any) {
return error.response.data;
return this.processErrorResponse(error);
}
}
}
Expand Down

0 comments on commit 6383eff

Please sign in to comment.