Skip to content

Commit 97549f1

Browse files
committed
Fix schema fetching error handling
1 parent 94e54fe commit 97549f1

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

packages/graphql-playground-react/src/state/sessions/fetchingSagas.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ function* runQuerySaga(action) {
176176
try {
177177
while (true) {
178178
const { value, error } = yield take(channel)
179-
if (value.extensions) {
179+
if (value && value.extensions) {
180180
const extensions = value.extensions
181181
yield put(setResponseExtensions(extensions))
182182
delete value.extensiosn
@@ -195,17 +195,23 @@ function* runQuerySaga(action) {
195195
}
196196
}
197197

198-
function formatError(error) {
198+
export function formatError(error, fetchingSchema: boolean = false) {
199+
const message = extractMessage(error)
200+
if (message === 'Failed to fetch') {
201+
const schemaMessage = fetchingSchema ? ' schema' : ''
202+
return { error: `${message}${schemaMessage}. Please check your connection` }
203+
}
204+
205+
return { error: message }
206+
}
207+
208+
function extractMessage(error) {
199209
if (error instanceof Error) {
200-
return {
201-
error: error.message,
202-
}
210+
return error.message
203211
}
204212

205213
if (typeof error === 'string') {
206-
return {
207-
error,
208-
}
214+
return error
209215
}
210216

211217
return error

packages/graphql-playground-react/src/state/sessions/reducers.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
import { getSelectedSessionId } from './selectors'
2626
import { getDefaultSession, defaultQuery } from '../../constants'
2727
import * as cuid from 'cuid'
28+
import { formatError } from './fetchingSagas'
2829

2930
export interface SessionStateProps {
3031
sessions: OrderedMap<string, Session>
@@ -308,7 +309,11 @@ const reducer = handleActions(
308309
responses: List([
309310
new ResponseRecord({
310311
resultID: cuid(),
311-
date: payload.error,
312+
date: JSON.stringify(
313+
formatError(payload.error, true),
314+
null,
315+
2,
316+
),
312317
time: new Date(),
313318
}),
314319
]),

0 commit comments

Comments
 (0)