Replies: 1 comment
-
|
Thanks @robkuz, I'm going to add something to the docs. htmx has an extension to convert JSON via templates, but I'd prefer not to go down that rabbit hole. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Yeah I know, I know.
but serously!
Let me explain.
I am using nestjs and as expected I am sending HTML across the wire almost all of the time.
However there is one scenario where I run into a hard block with nestjs, unpoly and the attempt to send html.
that is when the server receives unfixable formdata from the client that the Validation Pipes within nestjs reject the incoming data altogether. In such cases nestjs throws an exception returns always a JSON structure describing the error.
There are ways to circumvent that on the server side but that is really nasty and creates massive overhead.
So i opted to handle such case by creating the proper HTML on the server then throwing an exception using the HTML which then will be packaged as a JSON and on the client side I intercept the
onLoadedcallback, extract theresponse.textonstatus === 400then I try to parse the text as JSON. if that works I extract the HTML from the JSON an put this back into theresponse.textaltogether this looks like this
I think it would be cool if instead of that callback one could do something like this
up.render({target, url, params, failTarget: "#errors_dialog", method: "POST", returnType: "JSON", JSONPath: "error.message"})where upon unpoly parses the JSON and has a path to the property where the HTML is stored.
Now if you say all this isnt a good fit for unpoly - maybe you could add my example (maybe improved) to the docs.
It took me roughly a day to figure this out and others can benefit from my experiences
Best regards
Robert
Beta Was this translation helpful? Give feedback.
All reactions