Skip to content

Commit

Permalink
fix: do not require index sig on vars (#659)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonkuhrt authored Feb 3, 2024
1 parent fff4731 commit 8f926b8
Show file tree
Hide file tree
Showing 16 changed files with 510 additions and 493 deletions.
7 changes: 3 additions & 4 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
"typescript.tsdk": "node_modules/typescript/lib",
"typescript.enablePromptUseWorkspaceTsdk": true,
"editor.codeActionsOnSave": {
"source.addMissingImports": true,
"source.fixAll.eslint": true,
// Disable this because it will conflict with ESLint based import organizing.
"source.organizeImports": false
"source.addMissingImports": "explicit",
"source.fixAll.eslint": "explicit",
"source.organizeImports": "never"
}
}
29 changes: 29 additions & 0 deletions src/classes/ClientError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import type { GraphQLRequestContext, GraphQLResponse } from '../helpers/types.js'

export class ClientError extends Error {
public response: GraphQLResponse
public request: GraphQLRequestContext

constructor(response: GraphQLResponse, request: GraphQLRequestContext) {
const message = `${ClientError.extractMessage(response)}: ${JSON.stringify({
response,
request,
})}`

super(message)

Object.setPrototypeOf(this, ClientError.prototype)

this.response = response
this.request = request

// this is needed as Safari doesn't support .captureStackTrace
if (typeof Error.captureStackTrace === `function`) {
Error.captureStackTrace(this, ClientError)
}
}

private static extractMessage(response: GraphQLResponse): string {
return response.errors?.[0]?.message ?? `GraphQL Error (Code: ${response.status})`
}
}
Loading

0 comments on commit 8f926b8

Please sign in to comment.