Skip to content

Commit 4adc2c9

Browse files
authored
Deprecation: [@octokit/request-error] error.code is deprecated, use error.status (#6732)
* Deprecation: [@octokit/request-error] `error.code` is deprecated, use `error.status` Fixes #6708 * Fix tests
1 parent 33202d6 commit 4adc2c9

File tree

5 files changed

+13
-17
lines changed

5 files changed

+13
-17
lines changed

src/common/utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,11 @@ function isHookError(e: Error): e is HookError {
142142
return !!(e as any).errors;
143143
}
144144

145-
function hasFieldErrors(e: any): e is Error & { errors: { value: string; field: string; code: string }[] } {
145+
function hasFieldErrors(e: any): e is Error & { errors: { value: string; field: string; status: string }[] } {
146146
let areFieldErrors = true;
147147
if (!!e.errors && Array.isArray(e.errors)) {
148148
for (const error of e.errors) {
149-
if (!error.field || !error.value || !error.code) {
149+
if (!error.field || !error.value || !error.status) {
150150
areFieldErrors = false;
151151
break;
152152
}
@@ -177,7 +177,7 @@ export function formatError(e: HookError | any): string {
177177
if (e.message === 'Validation Failed' && hasFieldErrors(e)) {
178178
furtherInfo = e.errors
179179
.map(error => {
180-
return `Value "${error.value}" cannot be set for field ${error.field} (code: ${error.code})`;
180+
return `Value "${error.value}" cannot be set for field ${error.field} (code: ${error.status})`;
181181
})
182182
.join(', ');
183183
} else if (e.message.startsWith('Validation Failed:')) {

src/github/folderRepositoryManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1205,7 +1205,7 @@ export class FolderRepositoryManager extends Disposable {
12051205
};
12061206
} catch (e) {
12071207
Logger.error(`Fetching pull request with query failed: ${e}`, this.id);
1208-
if (e.code === 404) {
1208+
if (e.status === 404) {
12091209
// not found
12101210
vscode.window.showWarningMessage(
12111211
`Fetching pull requests for remote ${githubRepository.remote.remoteName} with query failed, please check if the repo ${repo?.full_name} is valid.`,

src/github/githubRepository.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -264,13 +264,14 @@ export class GitHubRepository extends Disposable {
264264
rsp = await gql.query<T>(query);
265265
} catch (e) {
266266
const logInfo = (query.query.definitions[0] as { name: { value: string } | undefined }).name?.value;
267-
Logger.error(`Error querying GraphQL API (${logInfo}): ${e.message}${e.graphQLErrors ? `. ${(e.graphQLErrors as GraphQLError[]).map(error => error.extensions?.code).join(',')}` : ''}`, this.id);
267+
const gqlErrors = e.graphQLErrors ? e.graphQLErrors as GraphQLError[] : undefined;
268+
Logger.error(`Error querying GraphQL API (${logInfo}): ${e.message}${gqlErrors ? `. ${gqlErrors.map(error => error.extensions?.code).join(',')}` : ''}`, this.id);
268269
if (legacyFallback) {
269270
query.query = legacyFallback.query;
270271
return this.query(query, ignoreSamlErrors);
271272
}
272273

273-
if (e.graphQLErrors && e.graphQLErrors.length && ((e.graphQLErrors as GraphQLError[]).some(error => error.extensions?.code === 'undefinedField')) && !this._areQueriesLimited) {
274+
if (gqlErrors && gqlErrors.length && (gqlErrors.some(error => error.extensions?.code === 'undefinedField')) && !this._areQueriesLimited) {
274275
// We're running against a GitHub server that doesn't support the query we're trying to run.
275276
// Switch to the limited schema and try again.
276277
this._areQueriesLimited = true;
@@ -587,7 +588,7 @@ export class GitHubRepository extends Disposable {
587588
};
588589
} catch (e) {
589590
Logger.error(`Fetching all pull requests failed: ${e}`, this.id);
590-
if (e.code === 404) {
591+
if (e.status === 404) {
591592
// not found
592593
vscode.window.showWarningMessage(
593594
`Fetching all pull requests for remote '${remote?.remoteName}' failed, please check if the repository ${remote?.owner}/${remote?.repositoryName} is valid.`,
@@ -626,7 +627,7 @@ export class GitHubRepository extends Disposable {
626627
}
627628
} catch (e) {
628629
Logger.error(`Fetching pull request for branch failed: ${e}`, this.id);
629-
if (e.code === 404) {
630+
if (e.status === 404) {
630631
// not found
631632
vscode.window.showWarningMessage(
632633
`Fetching pull request for branch for remote '${remote?.remoteName}' failed, please check if the repository ${remote?.owner}/${remote?.repositoryName} is valid.`,
@@ -891,7 +892,7 @@ export class GitHubRepository extends Disposable {
891892
try {
892893
Logger.debug(`Fetch authenticated user emails - enter`, this.id);
893894
const { octokit } = await this.ensure();
894-
const { data } = await octokit.call(octokit.api.users.listEmailsForAuthenticated, {});
895+
const { data } = await octokit.call(octokit.api.users.listEmailsForAuthenticatedUser, {});
895896
Logger.debug(`Fetch authenticated user emails - done`, this.id);
896897
return data.map(email => email.email);
897898
} catch (e) {

src/github/quickPicks.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -349,12 +349,7 @@ export async function getMilestoneFromQuickPick(folderRepositoryManager: FolderR
349349
await callback(milestone);
350350
}
351351
} catch (e) {
352-
if (e.errors && Array.isArray(e.errors) && e.errors.find(error => error.code === 'already_exists') !== undefined) {
353-
vscode.window.showErrorMessage(vscode.l10n.t('Failed to create milestone: The milestone already exists and might be closed'));
354-
}
355-
else {
356-
vscode.window.showErrorMessage(`Failed to create milestone: ${formatError(e)}`);
357-
}
352+
vscode.window.showErrorMessage(`Failed to create milestone: ${formatError(e)}`);
358353
}
359354
});
360355
});

src/test/common/utils.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ describe('utils', () => {
4242
});
4343

4444
it('should format an error with field errors', () => {
45-
const error = new HookError('Validation Failed', [{ field: 'title', value: 'garbage', code: 'custom' }]);
45+
const error = new HookError('Validation Failed', [{ field: 'title', value: 'garbage', status: 'custom' }]);
4646
assert.strictEqual(utils.formatError(error), 'Validation Failed: Value "garbage" cannot be set for field title (code: custom)');
4747
});
4848

4949
it('should format an error with custom ', () => {
50-
const error = new HookError('Validation Failed', [{ message: 'Cannot push to this repo', code: 'custom' }]);
50+
const error = new HookError('Validation Failed', [{ message: 'Cannot push to this repo', status: 'custom' }]);
5151
assert.strictEqual(utils.formatError(error), 'Cannot push to this repo');
5252
});
5353
});

0 commit comments

Comments
 (0)