Skip to content

Commit

Permalink
Merge branch 'main' into chore/use-vitest
Browse files Browse the repository at this point in the history
  • Loading branch information
kettanaito committed Nov 1, 2023
2 parents 9ec19ed + f6e5112 commit e7cd5cd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
7 changes: 5 additions & 2 deletions src/node/SetupServerApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { mergeRight } from '~/core/utils/internal/mergeRight'
import { handleRequest } from '~/core/utils/handleRequest'
import { devUtils } from '~/core/utils/internal/devUtils'
import { SetupServer } from './glossary'
import { isNodeException } from './utils/isNodeException'
import { isNodeExceptionLike } from './utils/isNodeExceptionLike'

const DEFAULT_LISTEN_OPTIONS: RequiredDeep<SharedOptions> = {
onUnhandledRequest: 'warn',
Expand Down Expand Up @@ -80,7 +80,10 @@ export class SetupServerApi
* which won't be printed anyway if `setMaxListeners` fails.
*/
if (
!(isNodeException(error) && error.code === 'ERR_INVALID_ARG_TYPE')
!(
isNodeExceptionLike(error) &&
error.code === 'ERR_INVALID_ARG_TYPE'
)
) {
throw error
}
Expand Down
10 changes: 0 additions & 10 deletions src/node/utils/isNodeException.ts

This file was deleted.

14 changes: 14 additions & 0 deletions src/node/utils/isNodeExceptionLike.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* Determines if the given value is shaped like a Node.js exception.
* Node.js exceptions have additional information, like
* the `code` and `errno` properties.
*
* In some environments, particularly jsdom/jest these may not
* instances of `Error` or its subclasses, despite being similar
* to them.
*/
export function isNodeExceptionLike(
error: unknown,
): error is NodeJS.ErrnoException {
return !!error && typeof error === 'object' && 'code' in error
}

0 comments on commit e7cd5cd

Please sign in to comment.