Comments (5)
Confirming I no longer get unhandled exceptions with IR... thanks!
from itty-router.
Confirming I no longer get unhandled exceptions with IR... thanks!
Awesome, glad to hear it! Btw, in general, I'm pretty terrible about noticing issues in time (got lucky tonight) - I'd def recommend joining our discord channel where the wonderful community folks are WAY faster to answer questions!
from itty-router.
Ahhhh ok excellent. I'm on v4.0.27. I'll upgrade and test it. Right those samples make sense too! Thanks, good stuff 👍
IttyRouter is freakin cool.... really like it
I love to hear that!
Brace yourself for some big changes (in a good way)! We have v4.3x
pending release, which will drastically streamline the boilerplate for Bun/Cloudflare Workers (the Router lineup increases a bit), plus an entire docs site revamp that i'm working on this weekend to match the release.
from itty-router.
Which version are you using? As of 4.2.x
, withContent
should not be throwing... it'll waterfall through attempts against json
-> formData
-> text
, with catches at each stage. There should be nothing you can do to accidentally throw during one of those.
As of 4.2.2
(released just now), the entire thing with correctly return undefined if no request.body exists (<4.2.1
returned empty string incorrectly, but still didn't throw).
Now, theoretically if you wanted to stay on the older version, you could do one of the following:
- Add a final catch block after the
handle/fetch
. This will return a well formed error response, but not one specific to your case:export default { fetch: (req, ...args) => router .fetch(req, ...args) .then(json) // example of downstream formatter .catch(error) // example of downstream catches, returning a 500 }
- Add your own middleware that catches :)
const withContentNoThrow = async (request) => { request.content = await request.json().catch() // won't throw } const withContentCustomThrow = async (request) => { try { request.content = await request.json() } catch(err) { return error(400, 'Could not parse request.json as JSON.') } }
Hope that helps!
from itty-router.
Ahhhh ok excellent. I'm on v4.0.27. I'll upgrade and test it. Right those samples make sense too! Thanks, good stuff 👍
IttyRouter is freakin cool.... really like it
from itty-router.
Related Issues (20)
- Setting up cron trigger? HOT 2
- cors functions are stateful HOT 8
- Nested routers ergonomics HOT 8
- createCors().corsify eats additional Set-Cookie headers HOT 3
- Does `json()` support `headers` in options? HOT 4
- `withContent` returns a 500 when no body is sent HOT 1
- CORS issue, no preflight request shown HOT 6
- PROPOSAL: CORS HOT 4
- multiple set-cookie headers are removed by corsify
- Corsify override http error code. HOT 3
- typescript compilation error when using itty-router 5.0.5 HOT 3
- Uncaught TypeError: (src_default.middleware ?? []) is not iterable HOT 4
- Issue with CORS when response is cached HOT 2
- TS compilation error when using itty-router 5.0.17 HOT 11
- withContent middleware fails on BunJS HOT 1
- Feedbdack on deprecation of router.handle HOT 2
- Requests in v5 are hanging, examples not working HOT 7
- Nesting route cannot handle request for static assets HOT 4
- Throw unexpected error
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from itty-router.