startgg-helper-browser 1.0.2 → 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 +30 -12
  2. package/package.json +6 -2
package/main.js CHANGED
@@ -11,21 +11,39 @@ export async function loadQuery(url, maxTries = null){
11
11
  }
12
12
  }
13
13
 
14
- function requestStartGG(schema, variables, token){
15
- return fetch('https://api.start.gg/gql/alpha', {
16
- method: 'POST',
17
- headers: {
18
- 'Content-Type': 'application/json',
19
- 'accept' : 'application/json',
20
- 'Authorization' : token
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
+
26
+ async function requestStartGG(schema, variables, token){
27
+ const response = await fetch('https://api.start.gg/gql/alpha', {
28
+ method: 'POST',
29
+ headers: {
30
+ 'Content-Type': 'application/json',
31
+ 'accept': 'application/json',
32
+ 'Authorization': token
21
33
  },
22
34
  body: JSON.stringify({
23
35
  'query': schema,
24
- 'variables' : variables
25
- }),
26
-
27
- })
28
- .then((response) => response.json())
36
+ 'variables': variables
37
+ }),
38
+ });
39
+ const json = await response.json();
40
+ if (!json){
41
+ throw "Empty response"
42
+ }
43
+ if (json.success === false){
44
+ throw new GraphQLError(response, {schema, variables});
45
+ }
46
+ return json.data;
29
47
  }
30
48
 
31
49
  export class SGGHelperClient {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "startgg-helper-browser",
3
- "version": "1.0.2",
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": {
@@ -24,5 +24,9 @@
24
24
  "dependencies": {
25
25
  "startgg-helper": "^1.0.2"
26
26
  },
27
- "type": "module"
27
+ "type": "module",
28
+ "devDependencies": {
29
+ "webpack": "^5.94.0",
30
+ "webpack-cli": "^5.1.4"
31
+ }
28
32
  }