awtrix-ts 1.3.1 → 1.4.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.
Files changed (2) hide show
  1. package/dist/index.js +9 -3
  2. package/package.json +4 -2
package/dist/index.js CHANGED
@@ -137,18 +137,24 @@ class Awtrix {
137
137
  await this.post(`custom?name=${name}`);
138
138
  }
139
139
  async get(endpoint) {
140
- const response = await fetch(`${this.url}/${endpoint}`);
141
- const data = await response.json();
140
+ const res = await fetch(`${this.url}/${endpoint}`);
141
+ if (!res.ok) {
142
+ throw new Error(`Failed when calling ${endpoint}: ${res.status}`);
143
+ }
144
+ const data = await res.json();
142
145
  return data;
143
146
  }
144
147
  async post(endpoint, data) {
145
- await fetch(`${this.url}/${endpoint}`, {
148
+ const res = await fetch(`${this.url}/${endpoint}`, {
146
149
  method: 'POST',
147
150
  headers: {
148
151
  'Content-Type': 'application/json',
149
152
  },
150
153
  ...(data ? { body: JSON.stringify(data) } : {}),
151
154
  });
155
+ if (!res.ok) {
156
+ throw new Error(`Failed when calling ${endpoint}: ${res.status}`);
157
+ }
152
158
  }
153
159
  }
154
160
  export { Awtrix };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "awtrix-ts",
3
- "version": "1.3.1",
3
+ "version": "1.4.0",
4
4
  "description": "TypeScript API for Awtrix LED Matrix Display",
5
5
  "repository": {
6
6
  "type": "git",
@@ -41,5 +41,7 @@
41
41
  "iot",
42
42
  "pixel-clock",
43
43
  "pixel-display"
44
- ]
44
+ ],
45
+ "license": "MIT",
46
+ "author": "gledrich"
45
47
  }