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

Commit 5a90738

Browse files
authored
feat: Merge pull request #27 from seamapi/feat-throw-malformed-input-errors
2 parents 575fde3 + e976e97 commit 5a90738

File tree

7 files changed

+221
-3
lines changed

7 files changed

+221
-3
lines changed

.github/workflows/dispatch-test-pr.yml

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

docs/modules.md

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

1313
- [SeamAPIError](classes/SeamAPIError.md)
1414
- [SeamActionAttemptError](classes/SeamActionAttemptError.md)
15+
- [SeamMalformedInputError](classes/SeamMalformedInputError.md)
1516
- [default](classes/default.md)
1617

1718
### Interfaces

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
"@swc/core": "1.2.133",
5454
"@types/lodash": "^4.14.179",
5555
"@types/node": "17.0.10",
56+
"@types/uuid": "8.3.4",
5657
"@types/yargs": "17.0.8",
5758
"ajv": "8.9.0",
5859
"ava": "4.0.1",
@@ -75,7 +76,8 @@
7576
"type-fest": "2.11.1",
7677
"typedoc": "0.22.12",
7778
"typedoc-plugin-markdown": "3.11.12",
78-
"typescript": "4.5.5"
79+
"typescript": "4.5.5",
80+
"uuid": "8.3.2"
7981
},
8082
"lint-staged": {
8183
"*.{ts,css,md,js,mjs}": "prettier --write"

src/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import axios, { AxiosInstance, AxiosRequestConfig } from "axios"
2-
import { SeamAPIError } from "./lib/api-error"
2+
import { SeamAPIError, SeamMalformedInputError } from "./lib/api-error"
33
import { Routes } from "./routes"
44
import { ErroredAPIResponse, SuccessfulAPIResponse } from "./types/globals"
55

@@ -73,6 +73,12 @@ class Seam extends Routes {
7373
return response.data
7474
} catch (error) {
7575
if (axios.isAxiosError(error) && error.response) {
76+
if (error.response.data.error.type === "invalid_input") {
77+
throw new SeamMalformedInputError(
78+
error.response.data.error.validation_errors
79+
)
80+
}
81+
7682
throw new SeamAPIError(
7783
error.response.status,
7884
(error.response.data as ErroredAPIResponse).error

src/lib/api-error.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,17 @@ export class SeamActionAttemptError extends Error {
3535
return `SeamActionAttemptError: ${this.type} performing ${this.action_type}: ${this.message}`
3636
}
3737
}
38+
39+
export class SeamMalformedInputError extends Error {
40+
constructor(public validationErrors: Record<string, unknown>) {
41+
super("Malformed input")
42+
43+
if (Error.captureStackTrace) {
44+
Error.captureStackTrace(this, this.constructor)
45+
}
46+
}
47+
48+
toString() {
49+
return `SeamMalformedInputError: ${JSON.stringify(this.validationErrors)}`
50+
}
51+
}

yarn.lock

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,11 @@
480480
"@types/node" "*"
481481
"@types/ssh2-streams" "*"
482482

483+
484+
version "8.3.4"
485+
resolved "https://registry.yarnpkg.com/@types/uuid/-/uuid-8.3.4.tgz#bd86a43617df0594787d38b735f55c805becf1bc"
486+
integrity sha512-c/I8ZRb51j+pYGAu5CrFMRxqZ2ke4y2grEBO5AUjgSkSk+qT2Ea+OdWElz/OiMf5MNpn2b17kuVBwZLQJXzihw==
487+
483488
"@types/yargs-parser@*":
484489
version "20.2.1"
485490
resolved "https://registry.yarnpkg.com/@types/yargs-parser/-/yargs-parser-20.2.1.tgz#3b9ce2489919d9e4fea439b76916abc34b2df129"
@@ -5184,6 +5189,11 @@ util-deprecate@^1.0.1, util-deprecate@~1.0.1:
51845189
resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf"
51855190
integrity sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=
51865191

5192+
5193+
version "8.3.2"
5194+
resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.2.tgz#80d5b5ced271bb9af6c445f21a1a04c606cefbe2"
5195+
integrity sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==
5196+
51875197
validate-npm-package-license@^3.0.1, validate-npm-package-license@^3.0.4:
51885198
version "3.0.4"
51895199
resolved "https://registry.yarnpkg.com/validate-npm-package-license/-/validate-npm-package-license-3.0.4.tgz#fc91f6b9c7ba15c857f4cb2c5defeec39d4f410a"

0 commit comments

Comments
 (0)