Fix session error

Fix "Cannot destructure property 'session_id' of 'session' as it is null" error
Sometimes with a large number of requests, an error occurs when searching for a session.
1. Session not found. "session === null"
2. Next, we try to create it, but we get into "catch", i.e. our "session" variable is "null". If we get the error "Unique constraint failed on the fields: (`session_uuid`)", then the session was created in another request and we need to get it.
pull/1454/head
Ruslan 2022-08-23 12:13:20 +02:00 committed by GitHub
parent 0f976be5d8
commit 776704f050
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 3 deletions

View File

@ -50,16 +50,19 @@ export async function getSession(req) {
device,
});
if (!session) {
return null;
}
} catch (e) {
if (!e.message.includes('Unique constraint')) {
throw e;
} else {
session = await getSessionByUuid(session_uuid);
}
}
}
if (!session) {
return null;
}
const { session_id } = session;
return {