startgg-helper-browser 1.1.1 → 1.1.3

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.
Files changed (2) hide show
  1. package/main.js +24 -4
  2. package/package.json +1 -1
package/main.js CHANGED
@@ -17,9 +17,27 @@ class GraphQLError extends Error {
17
17
  * @param {Response} response
18
18
  * @param {{schema: {}, variables: {}}} request
19
19
  */
20
- constructor(response, request){
21
- super("Received code " + response.status + " | " + JSON.stringify(request));
20
+ constructor(response, request, resBody){
21
+ let message = "";
22
+ if (resBody.message){
23
+ message = resBody.message + ` (error id ${resBody.errorId})\n`;
24
+ } else if (resBody.errors){
25
+ message = "Errors : \n";
26
+ for (let error of resBody.errors){
27
+ message += "- " + error.message + ` (error id ${error.errorId})\n`;
28
+ }
29
+ message += '\n';
30
+ }
31
+ super(
32
+ "Received code " + response.status + " \n " +
33
+ message +
34
+ "Original request : " + JSON.stringify(request)
35
+ )
36
+
37
+ //super("Received code " + response.status + " ; " + JSON.stringify(request));
22
38
  this.name = "GraphQLError"
39
+ this.response = response;
40
+ this.resBody = resBody;
23
41
  }
24
42
  }
25
43
 
@@ -40,10 +58,12 @@ async function requestStartGG(schema, variables, token){
40
58
  if (!json){
41
59
  throw "Empty response"
42
60
  }
43
- if (json.success === false){
44
- throw new GraphQLError(response, {schema, variables});
61
+ if (!json.data){
62
+ throw new GraphQLError(response, {schema, variables}, json);
45
63
  }
64
+
46
65
  return json.data;
66
+
47
67
  }
48
68
 
49
69
  export class SGGHelperClient {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "startgg-helper-browser",
3
- "version": "1.1.1",
3
+ "version": "1.1.3",
4
4
  "description": "A set of functions and classes useful to communicate with the start.gg API from a web app",
5
5
  "main": "main.js",
6
6
  "scripts": {