Skip to content

Commit 8922db0

Browse files
committed
fix: do not override existing error codes when no code is specified
1 parent 4b7b58a commit 8922db0

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

packages/meteor-lib/src/api/client.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,18 @@ export namespace ClientAPI {
4848
/** On error, provide a human-readable error message */
4949
error: UserError
5050
}
51+
5152
/**
52-
* Used to reply to the user that the action didn't succeed (but it's not bad enough to log it as an error)
53-
* @param errorMessage
53+
* Returns a `ClientResponseError` object from a given `UserError`.
54+
*
55+
* If no `errorCode` is provided, it defaults to `error.errorCode` which is 500 when not specified.
56+
*
57+
* @param error - The `UserError` instance containing error details.
58+
* @param errorCode - An optional error code to override the default `error.errorCode`.
59+
* @returns A `ClientResponseError` object containing the error and the resolved error code.
5460
*/
5561
export function responseError(error: UserError, errorCode?: number): ClientResponseError {
56-
return { error, errorCode: errorCode ?? 500 }
62+
return { error, errorCode: errorCode ?? error.errorCode }
5763
}
5864
export interface ClientResponseSuccess<Result> {
5965
/** On success, return success code (by default, use 200) */

0 commit comments

Comments
 (0)