Skip to content

Commit 045fa88

Browse files
committed
feat!: rename onRemoteError to onFunctionError, onLocalError to onGeneralError
This is a breaking change to a new feature that releases half an hour ago, the names were confusing, and this changes improves it. Supposely this shouldn't break anyone.
1 parent bb7ada5 commit 045fa88

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

src/index.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,23 +61,23 @@ export interface EventOptions<Remote> {
6161
/**
6262
* Custom error handler
6363
*
64-
* @deprecated use `onRemoteError` and `onLocalError` instead
64+
* @deprecated use `onFunctionError` and `onGeneralError` instead
6565
*/
6666
onError?: (error: Error, functionName: string, args: any[]) => boolean | void
6767

6868
/**
69-
* Custom error handler for errors occurred in remote functions
69+
* Custom error handler for errors occurred in local functions being called
7070
*
7171
* @returns `true` to prevent the error from being thrown
7272
*/
73-
onRemoteError?: (error: Error, functionName: string, args: any[]) => boolean | void
73+
onFunctionError?: (error: Error, functionName: string, args: any[]) => boolean | void
7474

7575
/**
76-
* Custom error handler for errors occurred in local functions or during serialization
76+
* Custom error handler for errors occurred during serialization or messsaging
7777
*
7878
* @returns `true` to prevent the error from being thrown
7979
*/
80-
onLocalError?: (error: Error, functionName?: string, args?: any[]) => boolean | void
80+
onGeneralError?: (error: Error, functionName?: string, args?: any[]) => boolean | void
8181

8282
/**
8383
* Custom error handler for timeouts
@@ -282,7 +282,7 @@ export function createBirpc<RemoteFunctions = Record<string, never>, LocalFuncti
282282
msg = deserialize(data) as RPCMessage
283283
}
284284
catch (e) {
285-
if (options.onLocalError?.(e as Error) !== true)
285+
if (options.onGeneralError?.(e as Error) !== true)
286286
throw e
287287
return
288288
}
@@ -310,8 +310,8 @@ export function createBirpc<RemoteFunctions = Record<string, never>, LocalFuncti
310310
// Error handling
311311
if (error && options.onError)
312312
options.onError(error, method, args)
313-
if (error && options.onRemoteError) {
314-
if (options.onRemoteError(error, method, args) === true)
313+
if (error && options.onFunctionError) {
314+
if (options.onFunctionError(error, method, args) === true)
315315
return
316316
}
317317

@@ -323,7 +323,7 @@ export function createBirpc<RemoteFunctions = Record<string, never>, LocalFuncti
323323
}
324324
catch (e) {
325325
error = e
326-
if (options.onLocalError?.(e as Error, method, args) !== true)
326+
if (options.onGeneralError?.(e as Error, method, args) !== true)
327327
throw e
328328
}
329329
}
@@ -332,7 +332,7 @@ export function createBirpc<RemoteFunctions = Record<string, never>, LocalFuncti
332332
post(serialize(<Response>{ t: TYPE_RESPONSE, i: msg.i, e: error }), ...extra)
333333
}
334334
catch (e) {
335-
if (options.onLocalError?.(e as Error, method, args) !== true)
335+
if (options.onGeneralError?.(e as Error, method, args) !== true)
336336
throw e
337337
}
338338
}

test/error.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import * as Bob from './bob'
77
type BobFunctions = typeof Bob
88
type AliceFunctions = typeof Alice
99

10-
it('on remote error', async () => {
10+
it('on function error', async () => {
1111
const channel = new MessageChannel()
1212

1313
let error: any
@@ -17,7 +17,7 @@ it('on remote error', async () => {
1717
{
1818
post: data => channel.port1.postMessage(data),
1919
on: fn => channel.port1.on('message', fn),
20-
onRemoteError(err, method, args) {
20+
onFunctionError(err, method, args) {
2121
error = { err, method, args }
2222
},
2323
},
@@ -66,7 +66,7 @@ it('on serialize error', async () => {
6666
},
6767
post: data => channel.port1.postMessage(data),
6868
on: fn => channel.port1.on('message', fn),
69-
onLocalError(err, method, args) {
69+
onGeneralError(err, method, args) {
7070
error = { err, method, args }
7171
return true
7272
},
@@ -112,7 +112,7 @@ it('on parse error', async () => {
112112
},
113113
post: data => channel.port1.postMessage(data),
114114
on: fn => channel.port1.on('message', fn),
115-
onLocalError(err, method, args) {
115+
onGeneralError(err, method, args) {
116116
error = { err, method, args }
117117
return true
118118
},

0 commit comments

Comments
 (0)