-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix compatibility with page and app router
- Loading branch information
1 parent
95794b3
commit ed22786
Showing
8 changed files
with
99 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import {isDynamicServerError} from '@/errors'; | ||
|
||
describe('errors', () => { | ||
type TypeGuardScenario = { | ||
error: any, | ||
expected: boolean, | ||
}; | ||
|
||
it.each<TypeGuardScenario>([ | ||
{ | ||
error: null, | ||
expected: false, | ||
}, | ||
{ | ||
error: undefined, | ||
expected: false, | ||
}, | ||
{ | ||
error: {}, | ||
expected: false, | ||
}, | ||
{ | ||
error: new Error(), | ||
expected: false, | ||
}, | ||
{ | ||
error: new class { | ||
public readonly digest = 'DYNAMIC_SERVER_USAGE'; | ||
}(), | ||
expected: false, | ||
}, | ||
{ | ||
error: new class DynamicServerError { | ||
public readonly digest = 'foo'; | ||
}(), | ||
expected: false, | ||
}, | ||
{ | ||
error: new class DynamicServerError { | ||
public readonly digest = 'DYNAMIC_SERVER_USAGE'; | ||
}(), | ||
expected: true, | ||
}, | ||
])('should return $expected for $error identifying a DynamicServerError', ({error, expected}) => { | ||
expect(isDynamicServerError(error)).toBe(expected); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export declare class DynamicServerError extends Error { | ||
public readonly digest = 'DYNAMIC_SERVER_USAGE'; | ||
} | ||
|
||
export function isDynamicServerError(error: unknown): error is DynamicServerError { | ||
return typeof error === 'object' | ||
&& error !== null | ||
&& error.constructor.name === 'DynamicServerError' | ||
&& 'digest' in error | ||
&& error.digest === 'DYNAMIC_SERVER_USAGE'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters