Skip to content

Commit 6bb7ed0

Browse files
committed
Update code
1 parent 3316cce commit 6bb7ed0

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

frontend/graphql-codegen.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,22 @@ import { CodegenConfig } from '@graphql-codegen/cli'
33
const PUBLIC_API_URL = process.env.PUBLIC_API_URL || 'http://localhost:8000'
44

55
export default (async (): Promise<CodegenConfig> => {
6-
const response = await fetch(`${PUBLIC_API_URL}/csrf/`, {
7-
method: 'GET',
8-
})
6+
let response
7+
8+
try {
9+
response = await fetch(`${PUBLIC_API_URL}/csrf/`, {
10+
method: 'GET',
11+
})
12+
} catch {
13+
/* eslint-disable no-console */
14+
console.log('Failed to fetch CSRF token: make sure the backend is running.')
15+
return
16+
}
917

1018
if (!response.ok) {
1119
throw new Error(`Failed to fetch CSRF token: ${response.status} ${response.statusText}`)
1220
}
13-
const data = await response.json()
14-
const csrfToken = data.csrftoken
21+
const csrfToken = (await response.json()).csrftoken
1522

1623
return {
1724
documents: ['src/**/*.{ts,tsx}', '!src/types/__generated__/**'],

0 commit comments

Comments
 (0)