@teamkeel/functions-runtime 0.371.1 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teamkeel/functions-runtime",
3
- "version": "0.371.1",
3
+ "version": "0.372.0",
4
4
  "description": "Internal package used by @teamkeel/sdk",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -134,8 +134,7 @@ class QueryBuilder {
134
134
 
135
135
  span.setAttribute("sql", builder.compile().sql);
136
136
 
137
- const row = await builder.executeTakeFirstOrThrow();
138
-
137
+ const row = await builder.executeTakeFirst();
139
138
  if (!row) {
140
139
  return null;
141
140
  }
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
- if (!e.error) {
30
- // it isnt wrapped
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
- const { error: originalError } = e;
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 originalError responds to 'code' then assume it has other pg error message keys
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 originalError) {
65
- const { code, detail, table } = originalError;
67
+ if ("code" in err) {
68
+ const { code, detail, table } = err;
66
69
 
67
70
  let rpcErrorCode, column, value;
68
- const [col, val] = parseKeyMessage(originalError.detail);
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 = originalError.column;
78
+ column = err.column;
76
79
  break;
77
80
  case "23503":
78
81
  rpcErrorCode = RuntimeErrors.ForeignKeyConstraintError;