Skip to content
This repository was archived by the owner on Nov 15, 2024. It is now read-only.

Commit bb1c2dd

Browse files
committed
Merge branch 'main' into feat-cli
2 parents ea93d6b + 94e145a commit bb1c2dd

File tree

6 files changed

+233
-16
lines changed

6 files changed

+233
-16
lines changed
Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
[seamapi](../README.md) / [Exports](../modules.md) / SeamActionAttemptError
2+
3+
# Class: SeamActionAttemptError
4+
5+
## Hierarchy
6+
7+
- `Error`
8+
9+
**`SeamActionAttemptError`**
10+
11+
## Table of contents
12+
13+
### Constructors
14+
15+
- [constructor](SeamActionAttemptError.md#constructor)
16+
17+
### Properties
18+
19+
- [action\_type](SeamActionAttemptError.md#action_type)
20+
- [message](SeamActionAttemptError.md#message)
21+
- [name](SeamActionAttemptError.md#name)
22+
- [stack](SeamActionAttemptError.md#stack)
23+
- [type](SeamActionAttemptError.md#type)
24+
- [prepareStackTrace](SeamActionAttemptError.md#preparestacktrace)
25+
- [stackTraceLimit](SeamActionAttemptError.md#stacktracelimit)
26+
27+
### Methods
28+
29+
- [toString](SeamActionAttemptError.md#tostring)
30+
- [captureStackTrace](SeamActionAttemptError.md#capturestacktrace)
31+
32+
## Constructors
33+
34+
### constructor
35+
36+
**new SeamActionAttemptError**(`type`, `message`, `action_type`)
37+
38+
#### Parameters
39+
40+
| Name | Type |
41+
| :------ | :------ |
42+
| `type` | `string` |
43+
| `message` | `string` |
44+
| `action_type` | `string` |
45+
46+
#### Overrides
47+
48+
Error.constructor
49+
50+
#### Defined in
51+
52+
[src/lib/api-error.ts:22](https://github.com/hello-seam/seamapi-javascript/blob/main/src/lib/api-error.ts#L22)
53+
54+
## Properties
55+
56+
### action\_type
57+
58+
**action\_type**: `string`
59+
60+
___
61+
62+
### message
63+
64+
**message**: `string`
65+
66+
#### Inherited from
67+
68+
Error.message
69+
70+
___
71+
72+
### name
73+
74+
**name**: `string`
75+
76+
#### Inherited from
77+
78+
Error.name
79+
80+
#### Defined in
81+
82+
node_modules/typescript/lib/lib.es5.d.ts:1022
83+
84+
___
85+
86+
### stack
87+
88+
`Optional` **stack**: `string`
89+
90+
#### Inherited from
91+
92+
Error.stack
93+
94+
#### Defined in
95+
96+
node_modules/typescript/lib/lib.es5.d.ts:1024
97+
98+
___
99+
100+
### type
101+
102+
**type**: `string`
103+
104+
___
105+
106+
### prepareStackTrace
107+
108+
`Static` `Optional` **prepareStackTrace**: (`err`: `Error`, `stackTraces`: `CallSite`[]) => `any`
109+
110+
#### Type declaration
111+
112+
▸ (`err`, `stackTraces`): `any`
113+
114+
Optional override for formatting stack traces
115+
116+
**`see`** https://v8.dev/docs/stack-trace-api#customizing-stack-traces
117+
118+
##### Parameters
119+
120+
| Name | Type |
121+
| :------ | :------ |
122+
| `err` | `Error` |
123+
| `stackTraces` | `CallSite`[] |
124+
125+
##### Returns
126+
127+
`any`
128+
129+
#### Inherited from
130+
131+
Error.prepareStackTrace
132+
133+
#### Defined in
134+
135+
node_modules/@types/node/globals.d.ts:11
136+
137+
___
138+
139+
### stackTraceLimit
140+
141+
`Static` **stackTraceLimit**: `number`
142+
143+
#### Inherited from
144+
145+
Error.stackTraceLimit
146+
147+
#### Defined in
148+
149+
node_modules/@types/node/globals.d.ts:13
150+
151+
## Methods
152+
153+
### toString
154+
155+
**toString**(): `string`
156+
157+
#### Returns
158+
159+
`string`
160+
161+
#### Defined in
162+
163+
[src/lib/api-error.ts:34](https://github.com/hello-seam/seamapi-javascript/blob/main/src/lib/api-error.ts#L34)
164+
165+
___
166+
167+
### captureStackTrace
168+
169+
`Static` **captureStackTrace**(`targetObject`, `constructorOpt?`): `void`
170+
171+
Create .stack property on a target object
172+
173+
#### Parameters
174+
175+
| Name | Type |
176+
| :------ | :------ |
177+
| `targetObject` | `object` |
178+
| `constructorOpt?` | `Function` |
179+
180+
#### Returns
181+
182+
`void`
183+
184+
#### Inherited from
185+
186+
Error.captureStackTrace
187+
188+
#### Defined in
189+
190+
node_modules/@types/node/globals.d.ts:4

docs/classes/default.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ Routes.accessCodes
7070

7171
#### Defined in
7272

73-
[src/routes.ts:162](https://github.com/hello-seam/seamapi-javascript/blob/main/src/routes.ts#L162)
73+
[src/routes.ts:168](https://github.com/hello-seam/seamapi-javascript/blob/main/src/routes.ts#L168)
7474

7575
___
7676

@@ -90,7 +90,7 @@ Routes.actionAttempts
9090

9191
#### Defined in
9292

93-
[src/routes.ts:219](https://github.com/hello-seam/seamapi-javascript/blob/main/src/routes.ts#L219)
93+
[src/routes.ts:227](https://github.com/hello-seam/seamapi-javascript/blob/main/src/routes.ts#L227)
9494

9595
___
9696

@@ -122,7 +122,7 @@ Routes.connectWebviews
122122

123123
#### Defined in
124124

125-
[src/routes.ts:142](https://github.com/hello-seam/seamapi-javascript/blob/main/src/routes.ts#L142)
125+
[src/routes.ts:148](https://github.com/hello-seam/seamapi-javascript/blob/main/src/routes.ts#L148)
126126

127127
___
128128

@@ -143,7 +143,7 @@ Routes.connectedAccounts
143143

144144
#### Defined in
145145

146-
[src/routes.ts:204](https://github.com/hello-seam/seamapi-javascript/blob/main/src/routes.ts#L204)
146+
[src/routes.ts:212](https://github.com/hello-seam/seamapi-javascript/blob/main/src/routes.ts#L212)
147147

148148
___
149149

@@ -164,7 +164,7 @@ Routes.devices
164164

165165
#### Defined in
166166

167-
[src/routes.ts:123](https://github.com/hello-seam/seamapi-javascript/blob/main/src/routes.ts#L123)
167+
[src/routes.ts:129](https://github.com/hello-seam/seamapi-javascript/blob/main/src/routes.ts#L129)
168168

169169
___
170170

@@ -187,7 +187,7 @@ Routes.locks
187187

188188
#### Defined in
189189

190-
[src/routes.ts:88](https://github.com/hello-seam/seamapi-javascript/blob/main/src/routes.ts#L88)
190+
[src/routes.ts:94](https://github.com/hello-seam/seamapi-javascript/blob/main/src/routes.ts#L94)
191191

192192
___
193193

@@ -209,7 +209,7 @@ Routes.workspaces
209209

210210
#### Defined in
211211

212-
[src/routes.ts:72](https://github.com/hello-seam/seamapi-javascript/blob/main/src/routes.ts#L72)
212+
[src/routes.ts:78](https://github.com/hello-seam/seamapi-javascript/blob/main/src/routes.ts#L78)
213213

214214
## Methods
215215

docs/modules.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
### Classes
1212

1313
- [SeamAPIError](classes/SeamAPIError.md)
14+
- [SeamActionAttemptError](classes/SeamActionAttemptError.md)
1415
- [default](classes/default.md)
1516

1617
### Interfaces

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"iot",
88
"device"
99
],
10-
"version": "2.0.0",
10+
"version": "2.0.1",
1111
"license": "MIT",
1212
"sideEffects": false,
1313
"main": "./cjs-wrapper.js",

src/lib/api-error.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,21 @@ export class SeamAPIError extends Error {
1717
return `SeamAPIError: ${this.status}, ${this.metadata?.message} (${this.metadata?.type})`
1818
}
1919
}
20+
21+
export class SeamActionAttemptError extends Error {
22+
constructor(
23+
public type: string,
24+
public message: string,
25+
public action_type: string
26+
) {
27+
super(`${type} performing ${action_type}: ${message}`)
28+
29+
if (Error.captureStackTrace) {
30+
Error.captureStackTrace(this, this.constructor)
31+
}
32+
}
33+
34+
toString() {
35+
return `SeamActionAttemptError: ${this.type} performing ${this.action_type}: ${this.message}`
36+
}
37+
}

src/routes.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
AccessCodeCreateScheduledRequest,
1414
ConnectWebviewCreateRequest,
1515
} from "./types/route-requests"
16+
import { SeamActionAttemptError } from "./lib/api-error"
1617

1718
type Promisable<T> = T | Promise<T>
1819

@@ -40,6 +41,13 @@ export abstract class Routes {
4041
if (actionAttempt.status !== "pending") break
4142
await new Promise((resolve) => setTimeout(resolve, 250))
4243
}
44+
if (actionAttempt.status === "error") {
45+
throw new SeamActionAttemptError(
46+
actionAttempt.error.type,
47+
actionAttempt.error.message,
48+
actionAttempt.action_type
49+
)
50+
}
4351
return actionAttempt as SuccessfulActionAttempt<T>
4452
}
4553

@@ -62,11 +70,9 @@ export abstract class Routes {
6270
"action_attempt",
6371
request
6472
)
65-
const successfulActionAttempt = await this.awaitActionAttempt<T>(
66-
pendingActionAttempt
67-
)
68-
if (innerObjectName === null) return successfulActionAttempt.result as any
69-
return (successfulActionAttempt as any).result[innerObjectName]
73+
const actionAttempt = await this.awaitActionAttempt<T>(pendingActionAttempt)
74+
if (innerObjectName === null) return actionAttempt.result as any
75+
return (actionAttempt as any).result[innerObjectName]
7076
}
7177

7278
public readonly workspaces = {
@@ -170,16 +176,18 @@ export abstract class Routes {
170176
const parsedParams: any = Object.assign({}, params)
171177

172178
if (
173-
typeof (params as AccessCodeCreateScheduledRequest).starts_at ===
174-
"object"
179+
(params as AccessCodeCreateScheduledRequest).starts_at === "object" &&
180+
(params as AccessCodeCreateScheduledRequest).starts_at !== null
175181
) {
176182
parsedParams.starts_at = (
177183
(params as AccessCodeCreateScheduledRequest).starts_at as Date
178184
).toISOString()
179185
}
180186

181187
if (
182-
typeof (params as AccessCodeCreateScheduledRequest).ends_at === "object"
188+
typeof (params as AccessCodeCreateScheduledRequest).ends_at ===
189+
"object" &&
190+
(params as AccessCodeCreateScheduledRequest).starts_at !== null
183191
) {
184192
parsedParams.ends_at = (
185193
(params as AccessCodeCreateScheduledRequest).ends_at as Date

0 commit comments

Comments
 (0)