Skip to content

Commit

Permalink
improve error structure
Browse files Browse the repository at this point in the history
  • Loading branch information
prostgles committed Jan 31, 2024
1 parent 14ddba4 commit ee79eba
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/DboBuilder/dboBuilderUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export function getSerializedClientErrorFromPGError(rawError: any, args: GetSeri

const errObject = {
...((!localParams || !localParams.socket) ? err : {}),
...pickKeys(err, ["column", "code", "table", "constraint", "hint"]),
...pickKeys(err, ["column", "code", "table", "constraint", "hint", "severity", "message", "name", "detail"]),
};
if (view?.dboBuilder?.constraints && errObject.constraint && !errObject.column) {
const constraint = view.dboBuilder.constraints
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "prostgles-server",
"version": "4.2.13",
"version": "4.2.14",
"description": "",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
23 changes: 22 additions & 1 deletion tests/isomorphicQueries.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import * as fs from "fs";
import { DBOFullyTyped } from "../dist/DBSchemaBuilder";
import type { DBHandlerClient } from "./client/index";
import { test, describe } from "node:test";
import { pickKeys } from "prostgles-types";


export const isomorphicQueries = async (db: DBOFullyTyped | DBHandlerClient, log: (msg: string, extra?: any) => void) => {
log("Starting isomorphic queries");

const isServer = !!(db.items as any).dboBuilder;
await describe("Isomorphic queries", async () => {
await test("Deleting stale data", async () => {
const itemsCount = await db.items.count!()
Expand All @@ -26,6 +27,26 @@ export const isomorphicQueries = async (db: DBOFullyTyped | DBHandlerClient, log

});

await test("Insert error structure", async () => {
const err = await db.items.insert!({ h: "a" }).catch(err => err);
const clientOnlyError = {
detail: 'Array value must start with "{" or dimension information.',
message: 'malformed array literal: "a"',
code: '22P02',
name: 'error',
severity: 'ERROR',
stack: [
'dbo.items.insert()'
]
}
if(isServer){
assert.deepStrictEqual(pickKeys(err, Object.keys(clientOnlyError)), clientOnlyError);
assert.equal(typeof err.query, "string");
} else {
assert.deepStrictEqual(err, clientOnlyError);
}
});

await test("Prepare data", async () => {
if(!db.sql) throw "db.sql missing";
const res = await db.items.insert!([{ name: "a" }, { name: "a" }, { name: "b" }], { returning: "*" });
Expand Down
2 changes: 1 addition & 1 deletion tests/server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ee79eba

Please sign in to comment.