Skip to content

Commit d52b272

Browse files
committed
Better GraphQL error logging
1 parent f2befce commit d52b272

2 files changed

Lines changed: 21 additions & 19 deletions

File tree

src/github/githubRepository.ts

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ import {
5555
User,
5656
} from './interface';
5757
import { IssueChangeEvent, IssueModel } from './issueModel';
58-
import { getErrorCode, LoggingOctokit } from './loggingOctokit';
58+
import { getErrorCode, GraphQLError, LoggingOctokit } from './loggingOctokit';
5959
import { PullRequestModel } from './pullRequestModel';
6060
import defaultSchema from './queries.gql';
6161
import * as extraSchema from './queriesExtra.gql';
@@ -162,18 +162,6 @@ export interface ForkDetails {
162162

163163
export 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-
177165
export enum CopilotWorkingStatus {
178166
NotCopilotIssue = 'NotCopilotIssue',
179167
InProgress = 'InProgress',

src/github/loggingOctokit.ts

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff 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+
3143
function 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
}

0 commit comments

Comments
 (0)