You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When the same `limiter` and `key` combination is used multiple times in a single request chain, the `ratelimit` middleware performs the rate limit check only once. This behavior follows the [Dedupe Middleware](/docs/recipes/dedupe-middleware) recipe. To disable deduplication, set `dedupe: false`.
94
94
:::
95
95
96
+
:::tip[Custom Error]
97
+
By default the middleware throws `TOO_MANY_REQUESTS`. Use `error` to throw your own, which is [defined](/docs/error-handling#orpcerror-compatibility) when its `code` and `data` match an error the procedure declares. A custom code responds with `400` unless you map it in [`errorStatusMap`](/docs/rpc/handler#custom-error-response).
Copy file name to clipboardExpand all lines: apps/content/docs/openapi/handler.mdx
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -94,7 +94,7 @@ const handler = new OpenAPIHandler(router, {
94
94
95
95
### Interceptors
96
96
97
-
These interceptors run only for matched requests, after routing and before error handling (but can't use `ORPCError` for [typesafe errors](/docs/error-handling#orpcerror-compatibility)). Use them when you need access to the matched procedure.
97
+
These interceptors run only for matched requests, after routing and before error handling, and can use `ORPCError` for [typesafe errors](/docs/error-handling#orpcerror-compatibility). Use them when you need access to the matched procedure.
98
98
99
99
:::tip
100
100
In most cases, `interceptors` are the best choice. They provide more context, are easier to work with, and run before error handling.
Copy file name to clipboardExpand all lines: apps/content/docs/plugins/get-method-csrf-protection.mdx
+10Lines changed: 10 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -43,6 +43,16 @@ const handler = new RPCHandler(router, {
43
43
The `handler` can be any supported oRPC handler, such as [RPCHandler](/docs/rpc/handler), [OpenAPIHandler](/docs/openapi/handler), or a custom one.
44
44
:::
45
45
46
+
## Custom Error
47
+
48
+
By default the plugin throws `FORBIDDEN`. Use `error` to throw your own, which is [defined](/docs/error-handling#orpcerror-compatibility) when its `code` and `data` match an error the matched procedure declares. A custom code responds with `400` unless you map it in [`errorStatusMap`](/docs/rpc/handler#custom-error-response).
49
+
50
+
```ts
51
+
newGetMethodCsrfProtectionHandlerPlugin({
52
+
error: () =>newORPCError('CSRF_BLOCKED'),
53
+
})
54
+
```
55
+
46
56
## Cookie Requirements
47
57
48
58
Mark authentication cookies `SameSite=Lax` or `SameSite=Strict` explicitly. Do not rely on browser defaults: only Chrome treats unmarked cookies as `Lax`, while Firefox and Safari treat them like `SameSite=None`, and Chrome still sends fresh unmarked cookies on cross-site `POST` for [two minutes](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Set-Cookie#lax).
Copy file name to clipboardExpand all lines: apps/content/docs/plugins/request-limit.mdx
+11Lines changed: 11 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -32,6 +32,17 @@ The `handler` can be any supported oRPC handler, such as [RPCHandler](/docs/rpc/
32
32
When used with [Request Compression](/docs/plugins/request-compression), `maxBodySize` applies to the **decompressed** payload size, not the compressed wire size.
33
33
:::
34
34
35
+
## Custom Error
36
+
37
+
By default the plugin throws `PAYLOAD_TOO_LARGE`. Use `error` to throw your own, which is [defined](/docs/error-handling#orpcerror-compatibility) when its `code` and `data` match an error the matched procedure declares. A custom code responds with `400` unless you map it in [`errorStatusMap`](/docs/rpc/handler#custom-error-response).
38
+
39
+
```ts
40
+
newRequestLimitHandlerPlugin({
41
+
maxBodySize: 1024*1024,
42
+
error: () =>newORPCError('TOO_BIG'),
43
+
})
44
+
```
45
+
35
46
## Peer Adapters
36
47
37
48
This plugin does not apply to peer-based adapters such as [WebSocket](/docs/adapters/websocket) and [Message Port](/docs/adapters/message-port). Each message reaches the handler fully loaded in memory, so there is no body left to limit. Instead, limit each message at the transport, and the total bytes per connection per minute, since a single call can span many messages (for example, an [AsyncIteratorObject](/docs/async-iterator-object) input). With Bun:
Copy file name to clipboardExpand all lines: apps/content/docs/plugins/tmp-file-upload.mdx
+9Lines changed: 9 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -105,6 +105,15 @@ A multipart body splits across the first two limits, fields and part headers aga
105
105
106
106
With all three limits configured, the plugin subsumes the [Request Limit Plugin](/docs/plugins/request-limit). When the [Request Compression Plugin](/docs/plugins/request-compression) is present, limits apply to the decompressed payload rather than the compressed wire size.
107
107
108
+
To reject with your own error instead, use `error`. It is [defined](/docs/error-handling#orpcerror-compatibility) when its `code` and `data` match an error the matched procedure declares. A custom code responds with `400` unless you map it in [`errorStatusMap`](/docs/rpc/handler#custom-error-response).
Copy file name to clipboardExpand all lines: apps/content/docs/recipes/validation-customization.mdx
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -100,7 +100,7 @@ const handler = new RPCHandler(router, {
100
100
101
101
As explained in the [error handling guide](/docs/error-handling#orpcerror-compatibility), if you throw an `ORPCError` whose `code` and `data` match an error defined with `.errors`, oRPC treats it the same as `errors.[code]`.
102
102
103
-
This does not work in [interceptors](/docs/rpc/handler#interceptors). Use [client interceptors](/docs/rpc/handler#client-interceptors) or[middleware](/docs/middleware) applied before `.input` or `.output` instead.
103
+
This works in [interceptors](/docs/rpc/handler#interceptors), [client interceptors](/docs/rpc/handler#client-interceptors), and[middleware](/docs/middleware) applied before `.input` or `.output`.
Copy file name to clipboardExpand all lines: apps/content/docs/rpc/handler.mdx
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -164,7 +164,7 @@ const handler = new RPCHandler(router, {
164
164
165
165
### Interceptors
166
166
167
-
These interceptors run only for matched requests, after routing and before error handling (but can't use `ORPCError` for [typesafe errors](/docs/error-handling#orpcerror-compatibility)). Use them when you need access to the matched procedure.
167
+
These interceptors run only for matched requests, after routing and before error handling, and can use `ORPCError` for [typesafe errors](/docs/error-handling#orpcerror-compatibility). Use them when you need access to the matched procedure.
168
168
169
169
:::tip
170
170
In most cases, `interceptors` are the best choice. They provide more context, are easier to work with, and run before error handling.
0 commit comments