startgg-helper-browser 1.1.0 → 1.1.1

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 +14 -4
  2. package/package.json +1 -1
package/main.js CHANGED
@@ -11,6 +11,18 @@ export async function loadQuery(url, maxTries = null){
11
11
  }
12
12
  }
13
13
 
14
+ class GraphQLError extends Error {
15
+ /**
16
+ *
17
+ * @param {Response} response
18
+ * @param {{schema: {}, variables: {}}} request
19
+ */
20
+ constructor(response, request){
21
+ super("Received code " + response.status + " | " + JSON.stringify(request));
22
+ this.name = "GraphQLError"
23
+ }
24
+ }
25
+
14
26
  async function requestStartGG(schema, variables, token){
15
27
  const response = await fetch('https://api.start.gg/gql/alpha', {
16
28
  method: 'POST',
@@ -28,10 +40,8 @@ async function requestStartGG(schema, variables, token){
28
40
  if (!json){
29
41
  throw "Empty response"
30
42
  }
31
- if (!json.success){
32
- throw new Error("GraphQL Error (code" + response.status + ")" + {response, request: {
33
- schema, variables
34
- }})
43
+ if (json.success === false){
44
+ throw new GraphQLError(response, {schema, variables});
35
45
  }
36
46
  return json.data;
37
47
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "startgg-helper-browser",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
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": {