customErrorAdapter
I have this errors.ts which i want to create my own custom errors, but where do i put my customErrorAdapter?
import { createSerializationAdapter } from "@tanstack/react-router"
export class NotMemberError extends Error {
public foo: string
public bar: bigint
constructor(message: string, options: { foo: string; bar: bigint }) {
super(message)
Object.setPrototypeOf(this, new.target.prototype)
this.name = this.constructor.name
this.foo = options.foo
this.bar = options.bar
}
}
export const customErrorAdapter = createSerializationAdapter({
key: "custom-error",
test: (v) => v instanceof NotMemberError,
toSerializable: ({ message, foo, bar }) => {
return {
message,
foo,
bar,
}
},
fromSerializable: ({ message, foo, bar }) => {
return new NotMemberError(message, { foo, bar })
},
})
2 Replies
optimistic-gold•3w ago
you figured this out right in the other thread, right?
magic-beigeOP•2w ago
No actually, even with a start.tsx file at /src - it did not help.