Skip to content

Commit

Permalink
Merge pull request #1270 from interval/credentials-send-io-call-error
Browse files Browse the repository at this point in the history
Support error messages for failed IO calls, use for credentials
  • Loading branch information
jacobmischka authored May 30, 2023
2 parents 9a4920e + 50a8b12 commit 83d20f2
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@interval/sdk",
"version": "1.3.0",
"version": "1.4.0-dev",
"description": "The frontendless framework for high growth companies. Interval automatically generates apps by inlining the UI in your backend code. It's a faster and more maintainable way to build internal tools, rapid prototypes, and more.",
"homepage": "https://interval.com",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion src/classes/IOClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ export class IOClient {
}
})
.catch(err => {
this.logger.warn('Failed resolving component immediately', err)
reject(err)
})

const response = {
Expand Down
1 change: 1 addition & 0 deletions src/classes/IOError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export type IOErrorKind =
| 'TRANSACTION_CLOSED'
| 'BAD_RESPONSE'
| 'RESPONSE_HANDLER_ERROR'
| 'RENDER_ERROR'

export default class IOError extends Error {
kind: IOErrorKind
Expand Down
22 changes: 20 additions & 2 deletions src/classes/IntervalClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,10 @@ export default class IntervalClient {
.then(response => {
toResend.delete(transactionId)

if (!response) {
if (
!response ||
(typeof response === 'object' && response.type === 'ERROR')
) {
// Unsuccessful response, don't try again
this.#pendingIOCalls.delete(transactionId)
}
Expand Down Expand Up @@ -1058,7 +1061,7 @@ export default class IntervalClient {
}
}

await intervalClient.#send(
const response = await intervalClient.#send(
'SEND_IO_CALL',
{
transactionId,
Expand All @@ -1068,6 +1071,21 @@ export default class IntervalClient {
attemptPeerSend,
}
)

if (
!response ||
(typeof response === 'object' && response.type === 'ERROR')
) {
let message = 'Error sending IO call.'
if (
typeof response === 'object' &&
response.type === 'ERROR' &&
response.message
) {
message = response.message
}
throw new IOError('RENDER_ERROR', message)
}
}

intervalClient.#transactionLoadingStates.delete(transactionId)
Expand Down
7 changes: 6 additions & 1 deletion src/internalRpcSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,12 @@ export const wsServerSchema = {
ioCall: z.string(),
skipClientCall: z.boolean().optional(),
}),
returns: z.boolean(),
returns: z.boolean().or(
z.object({
type: z.literal('ERROR'),
message: z.string().optional(),
})
),
},
SEND_PAGE: {
inputs: z.object({
Expand Down

0 comments on commit 83d20f2

Please sign in to comment.