Skip to content

Commit

Permalink
Fix transformResponse type
Browse files Browse the repository at this point in the history
  • Loading branch information
amanape committed Nov 25, 2024
1 parent 99bc965 commit 3469e9c
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions frontend/src/api/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,15 @@ export const retrieveGitHubUserRepositories = async (
page,
per_page,
},
transformResponse: (data: GitHubRepository[] | GitHubErrorReponse) => {
if (isGitHubErrorReponse(data)) {
throw new Error(data.message);
transformResponse: (data) => {
const parsedData: GitHubRepository[] | GitHubErrorReponse =
JSON.parse(data);

if (isGitHubErrorReponse(parsedData)) {
throw new Error(parsedData.message);
}

return data;
return parsedData;
},
});

Expand All @@ -48,12 +51,16 @@ export const retrieveGitHubUserRepositories = async (
*/
export const retrieveGitHubUser = async () => {
const response = await github.get<GitHubUser>("/user", {
transformResponse: (data: GitHubUser | GitHubErrorReponse) => {
if (isGitHubErrorReponse(data)) {
throw new Error(data.message);
transformResponse: (data) => {
const parsedData: GitHubUser | GitHubErrorReponse = JSON.parse(
data as string,
);

if (isGitHubErrorReponse(parsedData)) {
throw new Error(parsedData.message);
}

return data;
return parsedData;
},
});

Expand All @@ -80,12 +87,15 @@ export const retrieveLatestGitHubCommit = async (
params: {
per_page: 1,
},
transformResponse: (data: GitHubCommit[] | GitHubErrorReponse) => {
if (isGitHubErrorReponse(data)) {
throw new Error(data.message);
transformResponse: (data) => {
const parsedData: GitHubCommit[] | GitHubErrorReponse =
JSON.parse(data);

if (isGitHubErrorReponse(parsedData)) {
throw new Error(parsedData.message);
}

return data[0];
return parsedData[0];
},
},
);
Expand Down

0 comments on commit 3469e9c

Please sign in to comment.