MCPcopy
hub / github.com/refined-github/refined-github / getError

Function getError

source/github-helpers/api.tsx:122–177  ·  view source on GitHub ↗
(apiResponse: JsonObject)

Source from the content-addressed store, hash-verified

120};
121
122async function getError(apiResponse: JsonObject): Promise<RefinedGitHubApiError> {
123 const personalToken = await getToken();
124
125 if ((apiResponse.message as string)?.includes('API rate limit exceeded')) {
126 return new RefinedGitHubApiError(
127 'Rate limit exceeded.',
128 personalToken
129 ? 'It may be time for a walk! 🍃 🌞'
130 : 'Set your token in the options or take a walk! 🍃 🌞',
131 );
132 }
133
134 if (apiResponse.message === 'Bad credentials') {
135 return new RefinedGitHubApiError(
136 'The token seems to be incorrect or expired. Update it in the options.',
137 );
138 }
139
140 if ((apiResponse.message as string)?.includes('without `workflow` scope')) {
141 return new RefinedGitHubApiError(
142 'To update workflow files, you need to add the `workflow` scope to your token. Update your token at https://github.com/settings/tokens',
143 );
144 }
145
146 if ((apiResponse.message as string)?.includes('Resource not accessible by personal access token')) {
147 const error = new RefinedGitHubApiError(
148 'Your organization requires a specific type of token.',
149 );
150 error.richMessage = <>
151 Your organization requires a specific type of token.{' '}
152 <a
153 href="https://github.com/refined-github/refined-github/wiki/Security#token"
154 target="_blank"
155 rel="noreferrer"
156 style={{color: 'inherit', textDecoration: 'underline'}}
157 >
158 Fix…
159 </a>
160 </>;
161 return error;
162 }
163
164 const error = new RefinedGitHubApiError(
165 'Unable to fetch.',
166 personalToken
167 ? 'Ensure that your token has access to this repo.'
168 : 'Maybe adding a token in the options will fix this issue.',
169 // https://github.com/refined-github/refined-github/pull/9525
170 Array.isArray(apiResponse.errors)
171 // eslint-disable-next-line @typescript-eslint/no-base-to-string
172 ? apiResponse.errors.join('.\n')
173 : JSON.stringify(apiResponse, undefined, '\t'), // Beautify
174 );
175 error.response = apiResponse;
176 return error;
177}
178
179const v3uncached = async (

Callers 2

v3uncachedFunction · 0.85
v4uncachedFunction · 0.85

Calls 2

getTokenFunction · 0.85
includesMethod · 0.80

Tested by

no test coverage detected