@cofondateurauchomage/libs 1.1.120 → 1.1.121

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.
@@ -15,7 +15,9 @@ function asRecord(value) {
15
15
  * Construit les objets candidats à inspecter pour retrouver code/message :
16
16
  * - error
17
17
  * - error[dataInKeys]
18
+ * - error[codeKeys]
18
19
  * - error[dataInKeys][dataInKeys]
20
+ * - error[dataInKeys][codeKeys]
19
21
  */
20
22
  function getErrorCandidates(e) {
21
23
  const root = asRecord(e);
@@ -23,15 +25,17 @@ function getErrorCandidates(e) {
23
25
  return [];
24
26
  }
25
27
  const directData = (0, arrayUtils_1.compact)(dataInKeys.map(key => asRecord(root[key])));
28
+ const directCode = (0, arrayUtils_1.compact)(codeKeys.map(key => asRecord(root[key])));
26
29
  const nestedData = directData.flatMap(data => (0, arrayUtils_1.compact)(dataInKeys.map(key => asRecord(data[key]))));
27
- return [root, ...directData, ...nestedData];
30
+ const nestedCode = directData.flatMap(data => (0, arrayUtils_1.compact)(codeKeys.map(key => asRecord(data[key]))));
31
+ return [root, ...directData, ...directCode, ...nestedData, ...nestedCode];
28
32
  }
29
33
  /**
30
34
  * Helper pour récupérer le code number d'une erreur
31
35
  */
32
36
  function errCode(e) {
33
37
  const candidates = getErrorCandidates(e);
34
- const code = candidates?.flatMap(candidate => codeKeys.map(key => candidate[key])).find(value => typeof value === "number");
38
+ const code = candidates?.flatMap(candidate => [candidate, ...codeKeys.map(key => candidate[key])]).find(value => typeof value === "number");
35
39
  return code ?? 500;
36
40
  }
37
41
  /**
@@ -39,7 +43,7 @@ function errCode(e) {
39
43
  */
40
44
  function errStringCode(e) {
41
45
  const candidates = getErrorCandidates(e);
42
- const code = candidates?.flatMap(candidate => codeKeys.map(key => candidate[key])).find(value => typeof value === "string");
46
+ const code = candidates?.flatMap(candidate => [candidate, ...codeKeys.map(key => candidate[key])]).find(value => typeof value === "string");
43
47
  return code;
44
48
  }
45
49
  /**
@@ -47,6 +51,6 @@ function errStringCode(e) {
47
51
  */
48
52
  function errMessage(e) {
49
53
  const candidates = getErrorCandidates(e);
50
- const stringErr = candidates?.flatMap(candidate => messageKeys.map(key => candidate[key])).find(value => typeof value === "string");
54
+ const stringErr = candidates?.flatMap(candidate => [candidate, ...messageKeys.map(key => candidate[key])]).find(value => typeof value === "string");
51
55
  return stringErr ?? JSON.stringify(e).trim().slice(0, 100);
52
56
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cofondateurauchomage/libs",
3
- "version": "1.1.120",
3
+ "version": "1.1.121",
4
4
  "description": "",
5
5
  "main": "build/index",
6
6
  "scripts": {