Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion _examples/node-ts/server-fastify/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ app.get('/json', async (req, reply) => {
})

// Fallback 404 handler for all unmatched routes
app.setNotFoundHandler((req, reply) => {
app.setNotFoundHandler((_req, reply) => {
reply.code(404).send({ msg: 'not found' })
})

Expand Down
4 changes: 3 additions & 1 deletion _examples/node-ts/server-fastify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "node-ts-server",
"version": "1.0.0",
"description": "",
"type": "module",
"main": "index.js",
"scripts": {
"start": "tsx index.ts"
Expand All @@ -11,9 +12,10 @@
"license": "ISC",
"packageManager": "pnpm@10.17.1",
"devDependencies": {
"@fastify/cors": "^11.1.0",
"@tsconfig/strictest": "^2.0.6",
"@types/node": "^24.8.1",
"fastify": "^5.6.1",
"@fastify/cors": "^11.1.0",
"tsx": "^4.20.6",
"typescript": "^5.9.3"
}
Expand Down
8 changes: 8 additions & 0 deletions _examples/node-ts/server-fastify/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 19 additions & 22 deletions _examples/node-ts/server-fastify/server.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export const serveExampleRpc = async <Context>(service: ExampleServer<Context>,
if (!urlPath.startsWith('/rpc/')) return null
const parts = urlPath.split('/').filter(Boolean)
if (parts.length !== 3 || parts[0] !== 'rpc' || parts[1] !== 'Example') return null
const method = parts[2]
const method = parts[2]!
try {
const result = await dispatchExampleRequest(service, ctx, method, body)
return {
Expand Down Expand Up @@ -235,19 +235,16 @@ const validateType = (value: any, type: string) => {
type WebrpcErrorParams = { name?: string, code?: number, message?: string, status?: number, cause?: string }

export class WebrpcError extends Error {
name: string
code: number
message: string
status: number
cause?: string
Comment on lines -238 to -242
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are removed since they already are on the error object


constructor(error: WebrpcErrorParams = {}) {
super(error.message)
this.name = error.name || 'WebrpcEndpointError'
this.code = typeof error.code === 'number' ? error.code : 0
this.message = error.message || `endpoint error`
this.status = typeof error.status === 'number' ? error.status : 400
this.cause = error.cause
if (error.cause !== undefined) this.cause = error.cause
Object.setPrototypeOf(this, WebrpcError.prototype)
}

Expand All @@ -264,7 +261,7 @@ export class WebrpcEndpointError extends WebrpcError {
this.code = typeof error.code === 'number' ? error.code : 0
this.message = error.message || `endpoint error`
this.status = typeof error.status === 'number' ? error.status : 400
this.cause = error.cause
if (error.cause !== undefined) this.cause = error.cause
Object.setPrototypeOf(this, WebrpcEndpointError.prototype)
}
}
Expand All @@ -276,7 +273,7 @@ export class WebrpcRequestFailedError extends WebrpcError {
this.code = typeof error.code === 'number' ? error.code : -1
this.message = error.message || `request failed`
this.status = typeof error.status === 'number' ? error.status : 400
this.cause = error.cause
if (error.cause !== undefined) this.cause = error.cause
Object.setPrototypeOf(this, WebrpcRequestFailedError.prototype)
}
}
Expand All @@ -288,7 +285,7 @@ export class WebrpcBadRouteError extends WebrpcError {
this.code = typeof error.code === 'number' ? error.code : -2
this.message = error.message || `bad route`
this.status = typeof error.status === 'number' ? error.status : 404
this.cause = error.cause
if (error.cause !== undefined) this.cause = error.cause
Object.setPrototypeOf(this, WebrpcBadRouteError.prototype)
}
}
Expand All @@ -300,7 +297,7 @@ export class WebrpcBadMethodError extends WebrpcError {
this.code = typeof error.code === 'number' ? error.code : -3
this.message = error.message || `bad method`
this.status = typeof error.status === 'number' ? error.status : 405
this.cause = error.cause
if (error.cause !== undefined) this.cause = error.cause
Object.setPrototypeOf(this, WebrpcBadMethodError.prototype)
}
}
Expand All @@ -312,7 +309,7 @@ export class WebrpcBadRequestError extends WebrpcError {
this.code = typeof error.code === 'number' ? error.code : -4
this.message = error.message || `bad request`
this.status = typeof error.status === 'number' ? error.status : 400
this.cause = error.cause
if (error.cause !== undefined) this.cause = error.cause
Object.setPrototypeOf(this, WebrpcBadRequestError.prototype)
}
}
Expand All @@ -324,7 +321,7 @@ export class WebrpcBadResponseError extends WebrpcError {
this.code = typeof error.code === 'number' ? error.code : -5
this.message = error.message || `bad response`
this.status = typeof error.status === 'number' ? error.status : 500
this.cause = error.cause
if (error.cause !== undefined) this.cause = error.cause
Object.setPrototypeOf(this, WebrpcBadResponseError.prototype)
}
}
Expand All @@ -336,7 +333,7 @@ export class WebrpcServerPanicError extends WebrpcError {
this.code = typeof error.code === 'number' ? error.code : -6
this.message = error.message || `server panic`
this.status = typeof error.status === 'number' ? error.status : 500
this.cause = error.cause
if (error.cause !== undefined) this.cause = error.cause
Object.setPrototypeOf(this, WebrpcServerPanicError.prototype)
}
}
Expand All @@ -348,7 +345,7 @@ export class WebrpcInternalErrorError extends WebrpcError {
this.code = typeof error.code === 'number' ? error.code : -7
this.message = error.message || `internal error`
this.status = typeof error.status === 'number' ? error.status : 500
this.cause = error.cause
if (error.cause !== undefined) this.cause = error.cause
Object.setPrototypeOf(this, WebrpcInternalErrorError.prototype)
}
}
Expand All @@ -360,7 +357,7 @@ export class WebrpcClientAbortedError extends WebrpcError {
this.code = typeof error.code === 'number' ? error.code : -8
this.message = error.message || `request aborted by client`
this.status = typeof error.status === 'number' ? error.status : 400
this.cause = error.cause
if (error.cause !== undefined) this.cause = error.cause
Object.setPrototypeOf(this, WebrpcClientAbortedError.prototype)
}
}
Expand All @@ -372,7 +369,7 @@ export class WebrpcStreamLostError extends WebrpcError {
this.code = typeof error.code === 'number' ? error.code : -9
this.message = error.message || `stream lost`
this.status = typeof error.status === 'number' ? error.status : 400
this.cause = error.cause
if (error.cause !== undefined) this.cause = error.cause
Object.setPrototypeOf(this, WebrpcStreamLostError.prototype)
}
}
Expand All @@ -384,7 +381,7 @@ export class WebrpcStreamFinishedError extends WebrpcError {
this.code = typeof error.code === 'number' ? error.code : -10
this.message = error.message || `stream finished`
this.status = typeof error.status === 'number' ? error.status : 200
this.cause = error.cause
if (error.cause !== undefined) this.cause = error.cause
Object.setPrototypeOf(this, WebrpcStreamFinishedError.prototype)
}
}
Expand All @@ -401,7 +398,7 @@ export class UnauthorizedError extends WebrpcError {
this.code = typeof error.code === 'number' ? error.code : 1000
this.message = error.message || `Unauthorized access`
this.status = typeof error.status === 'number' ? error.status : 401
this.cause = error.cause
if (error.cause !== undefined) this.cause = error.cause
Object.setPrototypeOf(this, UnauthorizedError.prototype)
}
}
Expand All @@ -413,7 +410,7 @@ export class PermissionDeniedError extends WebrpcError {
this.code = typeof error.code === 'number' ? error.code : 1001
this.message = error.message || `Permission denied`
this.status = typeof error.status === 'number' ? error.status : 403
this.cause = error.cause
if (error.cause !== undefined) this.cause = error.cause
Object.setPrototypeOf(this, PermissionDeniedError.prototype)
}
}
Expand All @@ -425,7 +422,7 @@ export class SessionExpiredError extends WebrpcError {
this.code = typeof error.code === 'number' ? error.code : 1002
this.message = error.message || `Session expired`
this.status = typeof error.status === 'number' ? error.status : 403
this.cause = error.cause
if (error.cause !== undefined) this.cause = error.cause
Object.setPrototypeOf(this, SessionExpiredError.prototype)
}
}
Expand All @@ -437,7 +434,7 @@ export class GeoblockedError extends WebrpcError {
this.code = typeof error.code === 'number' ? error.code : 1003
this.message = error.message || `Geoblocked region`
this.status = typeof error.status === 'number' ? error.status : 451
this.cause = error.cause
if (error.cause !== undefined) this.cause = error.cause
Object.setPrototypeOf(this, GeoblockedError.prototype)
}
}
Expand All @@ -449,7 +446,7 @@ export class RateLimitedError extends WebrpcError {
this.code = typeof error.code === 'number' ? error.code : 1004
this.message = error.message || `Rate-limited. Please slow down.`
this.status = typeof error.status === 'number' ? error.status : 429
this.cause = error.cause
if (error.cause !== undefined) this.cause = error.cause
Object.setPrototypeOf(this, RateLimitedError.prototype)
}
}
Expand All @@ -461,7 +458,7 @@ export class CorsDisallowedError extends WebrpcError {
this.code = typeof error.code === 'number' ? error.code : 1005
this.message = error.message || `CORS disallowed. JWT can't be used from a web app.`
this.status = typeof error.status === 'number' ? error.status : 403
this.cause = error.cause
if (error.cause !== undefined) this.cause = error.cause
Object.setPrototypeOf(this, CorsDisallowedError.prototype)
}
}
Expand Down
4 changes: 1 addition & 3 deletions _examples/node-ts/server-fastify/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
{
"extends": "@tsconfig/strictest/tsconfig.json",
"compilerOptions": {
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"resolveJsonModule": true,
"types": ["node"]
},
Expand Down
4 changes: 2 additions & 2 deletions _examples/node-ts/server-hono/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "node-ts-server",
"version": "1.0.0",
"description": "",
"type": "module",
"main": "index.js",
"scripts": {
"start": "tsx index.ts"
Expand All @@ -12,11 +13,10 @@
"packageManager": "pnpm@10.17.1",
"devDependencies": {
"@hono/node-server": "^1.13.3",
"@tsconfig/strictest": "^2.0.6",
"@types/node": "^24.8.1",
"hono": "^4.4.7",
"tsx": "^4.20.6",
"typescript": "^5.9.3"
},
"dependencies": {
}
}
8 changes: 8 additions & 0 deletions _examples/node-ts/server-hono/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading