diff options
| author | Joe Carstairs <65492573+Sycamost@users.noreply.github.com> | 2023-12-24 10:49:40 +0000 |
|---|---|---|
| committer | Joe Carstairs <jcarstairs@scottlogic.com> | 2024-01-29 10:46:51 +0000 |
| commit | 2f7541ae836a99d9f189845547010e470e0efa8c (patch) | |
| tree | be36495f2e8bc07ac6aa2dbfe892e68d0b62c9a8 /api/db/_addUser.ts | |
| parent | abe4ef05eab70d65dbe9f8dc6fb94229c8a4cb12 (diff) | |
Improves error logging in database queries (#53)
Diffstat (limited to 'api/db/_addUser.ts')
| -rw-r--r-- | api/db/_addUser.ts | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/api/db/_addUser.ts b/api/db/_addUser.ts index ef72447..776391a 100644 --- a/api/db/_addUser.ts +++ b/api/db/_addUser.ts @@ -4,17 +4,19 @@ import { sql } from '@vercel/postgres'; import { USERS } from './_tables'; export default async function addUser(user: User) { + const query = ` + INSERT INTO ${USERS.name} ( + ${USERS.fields.id}, + ${USERS.fields.displayName} + ) VALUES ( + '${user.id}', + '${user.displayName}' + ); + `; + try { - await sql.query(` - INSERT INTO ${USERS.name} ( - ${USERS.fields.id}, - ${USERS.fields.displayName} - ) VALUES ( - '${user.id}', - '${user.displayName}' - ); - `); + await sql.query(query); } catch (err) { - throw new Error(`Failed to insert user into database: ${JSON.stringify(user)}.`, err); + throw new Error(`Failed to insert user into database: ${JSON.stringify(user)}. Query was ${query.replace(/\s+/g, ' ')}. ${err}`); } -}
\ No newline at end of file +} |
