Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 1 addition & 13 deletions src/github/githubRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ import {
User,
} from './interface';
import { IssueChangeEvent, IssueModel } from './issueModel';
import { getErrorCode, LoggingOctokit } from './loggingOctokit';
import { getErrorCode, GraphQLError, LoggingOctokit } from './loggingOctokit';
import { PullRequestModel } from './pullRequestModel';
import defaultSchema from './queries.gql';
import * as extraSchema from './queriesExtra.gql';
Expand Down Expand Up @@ -162,18 +162,6 @@ export interface ForkDetails {

export type IMetadata = OctokitCommon.ReposGetResponseData;

export enum GraphQLErrorType {
Unprocessable = 'UNPROCESSABLE',
}

export interface GraphQLError {
extensions?: {
code: string;
};
type?: GraphQLErrorType;
message?: string;
}

export enum CopilotWorkingStatus {
NotCopilotIssue = 'NotCopilotIssue',
Comment thread
alexr00 marked this conversation as resolved.
InProgress = 'InProgress',
Expand Down
26 changes: 20 additions & 6 deletions src/github/loggingOctokit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ interface RateLimitResult {
} | undefined;
}

export enum GraphQLErrorType {
Unprocessable = 'UNPROCESSABLE',
}

export interface GraphQLError {
extensions?: {
code: string;
Comment thread
alexr00 marked this conversation as resolved.
};
type?: GraphQLErrorType;
message?: string;
}

function isObject(value: unknown): value is Record<string, unknown> {
return typeof value === 'object' && value !== null;
}
Expand All @@ -47,12 +59,14 @@ export function getErrorCode(e: unknown): string | undefined {
}

const graphQLErrors = e.graphQLErrors;
if (Array.isArray(graphQLErrors)) {
const firstGraphQLError = graphQLErrors[0];
if (isObject(firstGraphQLError)) {
const extensions = firstGraphQLError.extensions;
if (isObject(extensions) && extensions.code !== undefined) {
return String(extensions.code);
if (Array.isArray(graphQLErrors) && graphQLErrors.length > 0) {
const firstGraphQLError = graphQLErrors[0] as GraphQLError | undefined;
if (firstGraphQLError) {
if (firstGraphQLError.extensions?.code !== undefined) {
return String(firstGraphQLError.extensions.code);
}
if (firstGraphQLError.type !== undefined) {
return String(firstGraphQLError.type);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/github/pullRequestModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { ConflictResolutionModel } from './conflictResolutionModel';
import { CredentialStore } from './credentials';
import { showEmptyCommitWebview } from './emptyCommitWebview';
import { FolderRepositoryManager } from './folderRepositoryManager';
import { GitHubRepository, GraphQLError, GraphQLErrorType } from './githubRepository';
import { GitHubRepository } from './githubRepository';
import {
AddCommentResponse,
AddReactionResponse,
Expand Down Expand Up @@ -66,7 +66,7 @@ import {
ReviewEventEnum,
} from './interface';
import { IssueChangeEvent, IssueModel } from './issueModel';
import { compareCommits } from './loggingOctokit';
import { compareCommits, GraphQLError, GraphQLErrorType } from './loggingOctokit';
import {
convertRESTPullRequestToRawPullRequest,
convertRESTReviewEvent,
Expand Down
Loading