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 })
},
})
3 Replies
national-gold•3w ago
in start.tsx
https://github.com/TanStack/router/blob/main/e2e/react-start/serialization-adapters/src/start.tsx
GitHub
router/e2e/react-start/serialization-adapters/src/start.tsx at main...
🤖 A client-first, server-capable, fully type-safe router and full-stack framework for the web (React and more). - TanStack/router
correct-apricotOP•3w ago
Aha, so I have to create this start.tsx file, since it does not exist
national-gold•3w ago
Correct