@stacksjs/error-handling 0.75.539 → 0.75.542
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -30,3 +30,22 @@ export declare function isUniqueViolation(err: unknown): boolean;
|
|
|
30
30
|
* server fault, so write paths answer it with a 422 instead of a 500.
|
|
31
31
|
*/
|
|
32
32
|
export declare function isNotNullViolation(err: unknown): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* True when the database refused a write to keep a foreign key intact, across
|
|
35
|
+
* SQLite, MySQL and Postgres:
|
|
36
|
+
*
|
|
37
|
+
* - SQLite: `SQLITE_CONSTRAINT_FOREIGNKEY`, or "FOREIGN KEY constraint failed"
|
|
38
|
+
* - MySQL: `errno: 1451` / `1217` (a parent row something still points at) and
|
|
39
|
+
* `1452` / `1216` (a child naming a parent that is not there)
|
|
40
|
+
* - Postgres: `code: '23503'` (foreign_key_violation) and `'23001'`
|
|
41
|
+
* (restrict_violation)
|
|
42
|
+
*
|
|
43
|
+
* Deleting a row other rows still point at is the case that matters to a
|
|
44
|
+
* caller: the row is fine and the request was understood, so it is a 409 the
|
|
45
|
+
* person can act on, not the 500 a generic catch turns it into.
|
|
46
|
+
*
|
|
47
|
+
* Checked by its own codes before the message, because SQLite reports a
|
|
48
|
+
* foreign key failure under the same `SQLITE_CONSTRAINT` family
|
|
49
|
+
* `isUniqueViolation` accepts as a whole.
|
|
50
|
+
*/
|
|
51
|
+
export declare function isForeignKeyViolation(err: unknown): boolean;
|
package/dist/unique-violation.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export function isUniqueViolation(err){const e=err;return e?.code==="SQLITE_CONSTRAINT_UNIQUE"||e?.code==="SQLITE_CONSTRAINT"||e
|
|
1
|
+
function hasSqlState(e,state){return e?.code===state||e?.errno===state}export function isUniqueViolation(err){const e=err;return e?.code==="SQLITE_CONSTRAINT_UNIQUE"||e?.code==="SQLITE_CONSTRAINT"||hasSqlState(e,"23505")||e?.errno===1062||/unique|duplicate/i.test(e?.message??"")}export function isNotNullViolation(err){const e=err;return e?.code==="SQLITE_CONSTRAINT_NOTNULL"||hasSqlState(e,"23502")||e?.errno===1048||e?.errno===1364||/not null constraint failed|cannot be null|null value in column|doesn't have a default value/i.test(e?.message??"")}export function isForeignKeyViolation(err){const e=err;return e?.code==="SQLITE_CONSTRAINT_FOREIGNKEY"||hasSqlState(e,"23503")||hasSqlState(e,"23001")||e?.errno===1451||e?.errno===1452||e?.errno===1216||e?.errno===1217||/foreign key constraint/i.test(e?.message??"")}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stacksjs/error-handling",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.75.
|
|
4
|
+
"version": "0.75.542",
|
|
5
5
|
"description": "Type safe error handling.",
|
|
6
6
|
"author": "Chris Breuer",
|
|
7
7
|
"contributors": [
|
|
@@ -58,16 +58,16 @@
|
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
60
|
"@bughq/sdk": "^0.3.0",
|
|
61
|
-
"@stacksjs/config": "0.75.
|
|
62
|
-
"@stacksjs/path": "0.75.
|
|
63
|
-
"@stacksjs/stx": "0.2.842",
|
|
64
|
-
"@stacksjs/types": "0.75.
|
|
61
|
+
"@stacksjs/config": "0.75.542",
|
|
62
|
+
"@stacksjs/path": "0.75.542",
|
|
63
|
+
"@stacksjs/stx": "^0.2.842",
|
|
64
|
+
"@stacksjs/types": "0.75.542",
|
|
65
65
|
"ts-error-handling": "^0.1.3",
|
|
66
66
|
"ts-syntax-highlighter": "^0.2.17"
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|
|
69
|
-
"@stacksjs/cli": "0.75.
|
|
70
|
-
"@stacksjs/validation": "0.75.
|
|
69
|
+
"@stacksjs/cli": "0.75.542",
|
|
70
|
+
"@stacksjs/validation": "0.75.542",
|
|
71
71
|
"better-dx": "^0.2.24"
|
|
72
72
|
},
|
|
73
73
|
"sideEffects": false
|