File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -55,7 +55,7 @@ import {
5555 User ,
5656} from './interface' ;
5757import { IssueChangeEvent , IssueModel } from './issueModel' ;
58- import { getErrorCode , LoggingOctokit } from './loggingOctokit' ;
58+ import { getErrorCode , GraphQLError , LoggingOctokit } from './loggingOctokit' ;
5959import { PullRequestModel } from './pullRequestModel' ;
6060import defaultSchema from './queries.gql' ;
6161import * as extraSchema from './queriesExtra.gql' ;
@@ -162,18 +162,6 @@ export interface ForkDetails {
162162
163163export type IMetadata = OctokitCommon . ReposGetResponseData ;
164164
165- export enum GraphQLErrorType {
166- Unprocessable = 'UNPROCESSABLE' ,
167- }
168-
169- export interface GraphQLError {
170- extensions ?: {
171- code : string ;
172- } ;
173- type ?: GraphQLErrorType ;
174- message ?: string ;
175- }
176-
177165export enum CopilotWorkingStatus {
178166 NotCopilotIssue = 'NotCopilotIssue' ,
179167 InProgress = 'InProgress' ,
Original file line number Diff line number Diff line change @@ -28,6 +28,18 @@ interface RateLimitResult {
2828 } | undefined ;
2929}
3030
31+ export enum GraphQLErrorType {
32+ Unprocessable = 'UNPROCESSABLE' ,
33+ }
34+
35+ export interface GraphQLError {
36+ extensions ?: {
37+ code : string ;
38+ } ;
39+ type ?: GraphQLErrorType ;
40+ message ?: string ;
41+ }
42+
3143function isObject ( value : unknown ) : value is Record < string , unknown > {
3244 return typeof value === 'object' && value !== null ;
3345}
@@ -47,12 +59,14 @@ export function getErrorCode(e: unknown): string | undefined {
4759 }
4860
4961 const graphQLErrors = e . graphQLErrors ;
50- if ( Array . isArray ( graphQLErrors ) ) {
51- const firstGraphQLError = graphQLErrors [ 0 ] ;
52- if ( isObject ( firstGraphQLError ) ) {
53- const extensions = firstGraphQLError . extensions ;
54- if ( isObject ( extensions ) && extensions . code !== undefined ) {
55- return String ( extensions . code ) ;
62+ if ( Array . isArray ( graphQLErrors ) && graphQLErrors . length > 0 ) {
63+ const firstGraphQLError = graphQLErrors [ 0 ] as GraphQLError | undefined ;
64+ if ( firstGraphQLError ) {
65+ if ( firstGraphQLError . extensions ?. code !== undefined ) {
66+ return String ( firstGraphQLError . extensions . code ) ;
67+ }
68+ if ( firstGraphQLError . type !== undefined ) {
69+ return String ( firstGraphQLError . type ) ;
5670 }
5771 }
5872 }
You can’t perform that action at this time.
0 commit comments