Skip to content

Commit 0c64f12

Browse files
committed
improve error messaging and handling
1 parent e602f8b commit 0c64f12

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

src/schemaHandler.js

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,10 @@ class SchemaHandler {
6868
).catch((err) => {
6969
if (err.errors) {
7070
for (const error of err?.errors) {
71-
if (error.message.includes("HTTP ERROR")) {
72-
// throw err;
73-
throw new Error(
74-
`There was an error dereferencing ${
75-
model.name
76-
} schema. \n\n dereferencing message: ${
77-
error.message
78-
} \n\n Model received: ${JSON.stringify(model)}`
79-
);
80-
}
71+
this.__HTTPError(error);
8172
}
73+
} else {
74+
this.__HTTPError(err);
8275
}
8376
return modelSchema;
8477
});
@@ -108,7 +101,11 @@ class SchemaHandler {
108101
throw new Error(
109102
`There was an error converting the ${
110103
model.name
111-
} schema. Model received looks like: \n\n${JSON.stringify(model)}`
104+
} schema. Model received looks like: \n\n${JSON.stringify(
105+
model
106+
)}. The convereted schema looks like \n\n${JSON.stringify(
107+
convertedSchemas
108+
)}`
112109
);
113110
}
114111
}
@@ -230,6 +227,19 @@ class SchemaHandler {
230227
Object.assign(this.openAPI, components);
231228
}
232229
}
230+
231+
__HTTPError(error) {
232+
if (error.message.includes("HTTP ERROR")) {
233+
// throw err;
234+
throw new Error(
235+
`There was an error dereferencing ${
236+
model.name
237+
} schema. \n\n dereferencing message: ${
238+
error.message
239+
} \n\n Model received: ${JSON.stringify(model)}`
240+
);
241+
}
242+
}
233243
}
234244

235245
module.exports = SchemaHandler;

0 commit comments

Comments
 (0)