Skip to content

Commit be5181e

Browse files
fix: error message not properly formatted (#188)
1 parent 7593d89 commit be5181e

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

gatsby-source-graphcms/src/gatsby-node.js

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { PLUGIN_NAME } from './util/constants'
2323
import { getImageBase64, getBase64DataURI } from './util/getImageBase64'
2424
import { getImageDominantColor } from './util/getDominantColor'
2525
import { getTracedSVG } from './util/getTracedSVG'
26+
import { reportPanic } from './util/reportPanic'
2627

2728
export function pluginOptionsSchema({ Joi }) {
2829
return Joi.object({
@@ -88,28 +89,34 @@ const createSourcingConfig = async (
8889
})
8990
.then((response) => {
9091
if (!response.ok) {
91-
return reporter.panic(
92-
`[${PLUGIN_NAME}]: Problem building GraphCMS nodes`,
93-
new Error(response.statusText)
92+
return reportPanic(
93+
1,
94+
'Problem building GraphCMS nodes',
95+
response.statusText,
96+
reporter
9497
)
9598
}
9699

97100
return response.json()
98101
})
99102
.then((response) => {
100103
if (response.errors) {
101-
return reporter.panic(
102-
`[${PLUGIN_NAME}]: Problem building GraphCMS nodes`,
103-
new Error(response.errors)
104+
return reportPanic(
105+
2,
106+
'Problem building GraphCMS nodes',
107+
JSON.stringify(response.errors, null, 2),
108+
reporter
104109
)
105110
}
106111

107112
return response
108113
})
109114
.catch((error) => {
110-
return reporter.panic(
111-
`[${PLUGIN_NAME}]: Problem building GraphCMS nodes`,
112-
new Error(error)
115+
return reportPanic(
116+
3,
117+
'Problem building GraphCMS nodes',
118+
JSON.stringify(error, null, 2),
119+
reporter
113120
)
114121
})
115122
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { PLUGIN_NAME } from './constants'
2+
3+
export function reportPanic(id, message, error, reporter) {
4+
return reporter.panic({
5+
context: {
6+
id,
7+
sourceMessage: `[${PLUGIN_NAME}]: ${message} \n\n ${new Error(error)}`,
8+
},
9+
})
10+
}

0 commit comments

Comments
 (0)