mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
Api: Bubble up the error to prevent unhandledRejection (#22231)
* Bubble up the error to prevent `unhandledRejection` * Add changeset * Remove unused async context * Catch callback errors Just in the off chance the bus.publish will throw an error --------- Co-authored-by: Rijk van Zanten <rijkvanzanten@me.com>
This commit is contained in:
5
.changeset/lemon-cobras-draw.md
Normal file
5
.changeset/lemon-cobras-draw.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@directus/api': patch
|
||||
---
|
||||
|
||||
Fixed an issue that could cause errors happening during schema retrieval to exit the process rather than return a 500
|
||||
@@ -68,22 +68,27 @@ export async function getSchema(
|
||||
if (currentProcessShouldHandleOperation === false) {
|
||||
logger.trace('Schema cache is prepared in another process, waiting for result.');
|
||||
|
||||
return new Promise((resolve) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const TIMEOUT = 10000;
|
||||
|
||||
const timeout: NodeJS.Timeout = setTimeout(async () => {
|
||||
const timeout: NodeJS.Timeout = setTimeout(() => {
|
||||
logger.trace('Did not receive schema callback message in time. Pulling schema...');
|
||||
callback();
|
||||
callback().catch(reject);
|
||||
}, TIMEOUT);
|
||||
|
||||
bus.subscribe(messageKey, callback);
|
||||
|
||||
async function callback() {
|
||||
if (timeout) clearTimeout(timeout);
|
||||
try {
|
||||
if (timeout) clearTimeout(timeout);
|
||||
|
||||
const schema = await getSchema(options, attempt + 1);
|
||||
resolve(schema);
|
||||
bus.unsubscribe(messageKey, callback);
|
||||
const schema = await getSchema(options, attempt + 1);
|
||||
resolve(schema);
|
||||
} catch (error) {
|
||||
reject(error);
|
||||
} finally {
|
||||
bus.unsubscribe(messageKey, callback);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user