Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

pullRequestDiffError.ts

36 lines1.1 KB

1import { msg, select } from "gt-react";
2​
3import { m, type MessageResolver } from "~/i18n/messages";
4​
5import type { ChangeRequestTermKind } from "./changeRequestTerm";
6​
7/** Diff failures currently include transport wrappers, so recognize the reason inside them. */
8export function describePullRequestDiffError(
9 error: string,
10 providerName: string,
11 term: ChangeRequestTermKind,
12 resolve: MessageResolver = m,
13) {
14 if (/\brate limit\b|\brate[-_]limited\b|\btoo many requests\b/i.test(error)) {
15 return {
16 title: resolve(msg`${{ providerName }} rate limit reached`),
17 description: resolve(
18 msg`${{ providerName }} is temporarily limiting requests, so this diff couldn't be loaded. Try again after the limit resets, or view the changes on ${{ providerName }}.`,
19 ),
20 };
21 }
22​
23 return {
24 title: resolve(msg("Couldn't load the changes")),
25 description: resolve(
26 msg`The environment couldn't load this ${select(
27 { term },
28 {
29 mr: "merge request",
30 cr: "change request",
31 other: "pull request",
32 },
33 )}'s diff. Try again, or view the changes on ${{ providerName }}.`,
34 ),
35 };