Open edoardo-bluframe opened 6 months ago
@edoardo-bluframe If you can setup a codepen example, or a repo reproducing this issue, that'd be great. Yes, feel free to open a PR if you think you know how to fix the issue! If it's found to be an issue, this seems like a good find. Thank you!
Guidance on PRs:
Runtime
node.js
Runtime version
18+
Module version
21.3.3
Last module version without issue
No response
Used with
No response
Any other relevant information
No response
What are you trying to achieve or the steps to reproduce?
Set multipart payload validation:
Pass a payload larger than limit via
fetch
from webExpect to handle 413 when
response.status === 413
What was the result you got?
Generic error
What result did you expect?
Image too large!
The problem here is actually in
hapijs/pez
and the way it handlesmaxBytes
- and other multipart errorspez
hasn't been touched in a year and a half though and has near zero activity, but it is officially part of Hapi so I raised it here where activity is actually happening :smile:On line 136 of
lib/index.js
inhapijs/pez
:This works but it happens before the actual Hapi validation occurs. I understand that multipart is being parsed before but this doesn't work with the new
fetch
APIFrom MDN Docs:
Every other validation in Hapi - say within
failAction
- behaves exactly as thefetch
API expects. Request fails with!response.ok
and response contains bothresponse.statusText
andresponse.status
Because of how early
hapijs/pez
throws the error thefetch
API actually interprets it as a lower level error.fetch
actuallythrows
and never gets to the!response.ok
partThat would actually be okay as we can catch it, if it wasn't that that way we completely lose
statusText
andstatus
and those are... essential for actually displaying a formatted error say in the UI. This example hasconsole.error
for simplicityWe use
hapi
in production everywhere for our projects - I really likehapi
:blush: - and we just ran into this oneI know
hapijs/pez
doesn't get worked on a lot but this is a pretty major issue for UI/UXI can help with a PR if you want me to - maybe a little guidance on best practices?