@teamkeel/functions-runtime 0.371.0 → 0.372.0
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.
- package/package.json +1 -1
- package/src/QueryBuilder.js +1 -2
- package/src/errors.js +23 -20
package/package.json
CHANGED
package/src/QueryBuilder.js
CHANGED
package/src/errors.js
CHANGED
|
@@ -26,25 +26,13 @@ const RuntimeErrors = {
|
|
|
26
26
|
|
|
27
27
|
// errorToJSONRPCResponse transforms a JavaScript Error instance (or derivative) into a valid JSONRPC response object to pass back to the Keel runtime.
|
|
28
28
|
function errorToJSONRPCResponse(request, e) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
if (e instanceof PermissionError) {
|
|
29
|
+
switch (e.constructor.name) {
|
|
30
|
+
case "PermissionError":
|
|
33
31
|
return createJSONRPCErrorResponse(
|
|
34
32
|
request.id,
|
|
35
33
|
RuntimeErrors.PermissionError,
|
|
36
34
|
e.message
|
|
37
35
|
);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return createJSONRPCErrorResponse(
|
|
41
|
-
request.id,
|
|
42
|
-
RuntimeErrors.UnknownError,
|
|
43
|
-
e.message
|
|
44
|
-
);
|
|
45
|
-
}
|
|
46
|
-
// we want to switch on instanceof but there is no way to do that in js, so best to check the constructor class of the error
|
|
47
|
-
switch (e.error.constructor.name) {
|
|
48
36
|
// Any error thrown in the ModelAPI class is
|
|
49
37
|
// wrapped in a DatabaseError in order to differentiate 'our code' vs the user's own code.
|
|
50
38
|
case "NoResultError":
|
|
@@ -56,23 +44,38 @@ function errorToJSONRPCResponse(request, e) {
|
|
|
56
44
|
e.message
|
|
57
45
|
);
|
|
58
46
|
case "DatabaseError":
|
|
59
|
-
|
|
47
|
+
let err = e;
|
|
48
|
+
|
|
49
|
+
// If wrapped error then unwrap
|
|
50
|
+
if (e instanceof DatabaseError) {
|
|
51
|
+
err = e.error;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (err.constructor.name == "NoResultError") {
|
|
55
|
+
return createJSONRPCErrorResponse(
|
|
56
|
+
request.id,
|
|
57
|
+
|
|
58
|
+
// to be matched to https://github.com/teamkeel/keel/blob/e3115ffe381bfc371d4f45bbf96a15072a994ce5/runtime/actions/update.go#L54-L54
|
|
59
|
+
RuntimeErrors.RecordNotFoundError,
|
|
60
|
+
err.message
|
|
61
|
+
);
|
|
62
|
+
}
|
|
60
63
|
|
|
61
|
-
// if the
|
|
64
|
+
// if the error contains 'code' then assume it has other pg error message keys
|
|
62
65
|
// todo: make this more ironclad.
|
|
63
66
|
// when using lib-pq, should match https://github.com/brianc/node-postgres/blob/master/packages/pg-protocol/src/parser.ts#L371-L386
|
|
64
|
-
if ("code" in
|
|
65
|
-
const { code, detail, table } =
|
|
67
|
+
if ("code" in err) {
|
|
68
|
+
const { code, detail, table } = err;
|
|
66
69
|
|
|
67
70
|
let rpcErrorCode, column, value;
|
|
68
|
-
const [col, val] = parseKeyMessage(
|
|
71
|
+
const [col, val] = parseKeyMessage(err.detail);
|
|
69
72
|
column = col;
|
|
70
73
|
value = val;
|
|
71
74
|
|
|
72
75
|
switch (code) {
|
|
73
76
|
case "23502":
|
|
74
77
|
rpcErrorCode = RuntimeErrors.NotNullConstraintError;
|
|
75
|
-
column =
|
|
78
|
+
column = err.column;
|
|
76
79
|
break;
|
|
77
80
|
case "23503":
|
|
78
81
|
rpcErrorCode = RuntimeErrors.ForeignKeyConstraintError;
|