Skip to content

Commit

Permalink
Merge pull request #75 from middlewarehq/ambientTS
Browse files Browse the repository at this point in the history
Ambient ts
  • Loading branch information
samad-yar-khan authored Dec 11, 2023
2 parents 5001e05 + 992b103 commit fc9d6cd
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/analytics/pr-analytics.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { ResponseError } from '@/utils/errors';
import { PullRequestEdge, PullRequest } from '../api-helpers/exapi-sdk/types';
import { getTopNKeys } from './utils';

export const getPRListAndMonthlyCountsFromGqlResponse = (
edges?: PullRequestEdge[][]
) => {
if (!edges) throw new Error('No data found to calculate stats');
if (!edges) throw new ResponseError('No data found to calculate stats', 404);

const flat_prs = edges.flat().map((pr_node) => pr_node.node);
const prs_monthly_counts = edges.map((monthly_prs) => monthly_prs.length);
Expand Down
5 changes: 2 additions & 3 deletions src/pages/api/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,9 @@ const fetchAndDownloadImageBuffer = async (
);
}
console.log(chalk.green('Successfully sent buffer to client'));
} catch (error) {
// console.error('Error fetching or sending buffer:', error);
} catch (error: any) {
console.log(chalk.red('Error fetching or sending buffer:'), error);
res.status(500).json({ error: 'Internal Server Error' });
res.status(error.status || 500).json({ message: error.message });
}
};

Expand Down
9 changes: 9 additions & 0 deletions src/utils/errors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export class ResponseError extends Error {
status: number;
constructor(msg: string, status?: number) {
super();
this.name = 'ResponseError';
this.status = status || 400;
this.message = msg;
}
}

0 comments on commit fc9d6cd

Please sign in to comment.