Open History to see the last commit
1import { createSerializationAdapter } from '@tanstack/solid-router'
2β
3export class CustomError extends Error {
4 public foo: string
5 public bar: bigint
6β
7 constructor(message: string, options: { foo: string; bar: bigint }) {
8 super(message)
9β
10 Object.setPrototypeOf(this, new.target.prototype)
11β
12 this.name = this.constructor.name
13 this.foo = options.foo
14 this.bar = options.bar
15 }
16}
17β
18export const customErrorAdapter = createSerializationAdapter({
19 key: 'custom-error',
20 test: (v) => v instanceof CustomError,
21 toSerializable: ({ message, foo, bar }) => {
22 return {
23 message,
24 foo,
25 bar,
26 }
27 },
28 fromSerializable: ({ message, foo, bar }) => {
29 return new CustomError(message, { foo, bar })
30 },
31})