Skip to content

Commit

Permalink
fix(feeds): Better handling Store API authentication errors on GitHub…
Browse files Browse the repository at this point in the history
… API proxy
  • Loading branch information
leomp12 committed Dec 4, 2024
1 parent 85bdcae commit f655904
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions packages/feeds/src/firebase/proxy-github.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Request, Response } from 'firebase-functions/v1';
import type { ApiError } from '@cloudcommerce/api';
import api from '@cloudcommerce/api';
import { logger } from '@cloudcommerce/firebase/lib/config';

Expand Down Expand Up @@ -28,9 +29,21 @@ const proxyGithubApi = async (req: Request, res: Response) => {
res.status(401).send('Access token is required on Authorization header');
return;
}
const { data: authUser } = await api.get('authentications/me', { accessToken });
if (!authUser.edit_storefront) {
res.status(401).send('Your auth user does not have permission to edit storefront');
try {
const { data: authUser } = await api.get('authentications/me', { accessToken });
if (!authUser.edit_storefront) {
res.status(401).send('Your auth user does not have permission to edit storefront');
return;
}
} catch (_err: any) {
const error = _err as ApiError;
if (error.statusCode && error.statusCode >= 400 && error.statusCode < 500) {
res.status(error.statusCode);
res.send(error.response?.data || 'Could not authenticate to Store API');
return;
}
res.sendStatus(500);
logger.error(error);
return;
}
const url = 'https://api.github.com'
Expand Down Expand Up @@ -88,8 +101,8 @@ const proxyGithubApi = async (req: Request, res: Response) => {
}
}
} catch (err) {
logger.error(err);
res.sendStatus(500);
logger.error(err);
}
clearTimeout(timer);
};
Expand Down

0 comments on commit f655904

Please # to comment.