@@ -37,16 +37,6 @@ async function invokeRespec(url: URL, params: URLSearchParams) {
3737 disableGPU : true ,
3838 } ) ;
3939
40- // Mimic respec CLI's haltonerror / haltonwarning behavior
41- const dieOn = params . get ( "die-on" ) ;
42- if (
43- ( errors . length && dieOn && dieOn !== "nothing" ) ||
44- ( ( errors . length || warnings . length ) && dieOn === "everything" )
45- ) {
46- throw new SpecGeneratorError (
47- `Did not generate, due to errors exceeding the allowed error level.` ,
48- ) ;
49- }
5040 return { html, errors, warnings } ;
5141 } catch ( err ) {
5242 throw new SpecGeneratorError ( err . message ) ;
@@ -169,7 +159,19 @@ export async function generateRespec(result: ValidateParamsResult) {
169159 const { html, errors, warnings } = await invokeRespec ( specUrl , params ) ;
170160 res . setHeader ( "x-errors-count" , errors . length ) ;
171161 res . setHeader ( "x-warnings-count" , warnings . length ) ;
172- res . send ( html ) ;
162+
163+ // Mimic respec CLI's haltonerror / haltonwarning behavior
164+ const dieOn = params . get ( "die-on" ) ;
165+ if (
166+ ( errors . length && dieOn && dieOn !== "nothing" ) ||
167+ ( ( errors . length || warnings . length ) && dieOn === "everything" )
168+ ) {
169+ res . status ( 500 ) . json ( {
170+ error : `Did not generate, due to errors exceeding the allowed error level.` ,
171+ } ) ;
172+ } else {
173+ res . send ( html ) ;
174+ }
173175 } catch ( err ) {
174176 res . status ( err . status ) . json ( { error : err . message } ) ;
175177 } finally {
0 commit comments