Skip to content

Commit

Permalink
Check for status 401 in the each services
Browse files Browse the repository at this point in the history
  • Loading branch information
KBandipo committed Sep 10, 2024
1 parent f267f92 commit 46f22a4
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions @api-server/api/app.service.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { Request } from 'express';
import { unauthorizedErr } from '../lib/errors/Errors';

export const getIssuesService = async () => {
const response = await fetch(`${process.env.REPO_API_URL}/issues`, {
headers: {
Authorization: `Bearer ${process.env.GITHUB_PERSONAL_ACCESS_TOKEN}`,
},
});
if (response.status === 401) {
unauthorizedErr("Unauthorized: Can't access this resource");
}
const data = await response.json();
return data;
}
Expand All @@ -23,6 +27,11 @@ export const createIssueService = async (req: Request) => {
body: body + '\n\n' + '#' + '\n' + '> Submitted via **Collabocate** [[GitHubSync]](https://github.com/collabo-community/collabocate)',
}),
});

if (response.status === 401) {
unauthorizedErr("Unauthorized: Can't access this resource");
}

const data = await response.json();
return data;
}
Expand All @@ -33,6 +42,11 @@ export const getPullRequestsService = async () => {
Authorization: `Bearer ${process.env.GITHUB_PERSONAL_ACCESS_TOKEN}`,
},
});

if (response.status === 401) {
unauthorizedErr("Unauthorized: Can't access this resource");
}

const data = await response.json();
return data;
}
Expand All @@ -44,6 +58,11 @@ export const getRepositoriesService = async () => {
},
}
);

if (response.status === 401) {
unauthorizedErr("Unauthorized: Can't access this resource");
}

const data = await response.json();
return data;
}

0 comments on commit 46f22a4

Please sign in to comment.