question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Handle POST response body of `""`

See original GitHub issue

I have a situation where my hosting provider (fly) responds to an action request with a 502 that doesn’t even get to my server (I think) so the useActionData() value is '' 😱

Because Remix doesn’t have control over this, I think I need to just always handle the case where data is not an object… I guess I could test for '' and change it to undefined 🤔 Might be nice if Remix did this out of the box. The reason this is a problem is because I do data?.errors.generalError and that blows up because it’s trying to access generalError on errors on an empty string (and errors is is undefined).

In any case, I think that one of two things need to happen:

  1. The useActionData generic should be function useActionData<T = AppData>(): T | undefined | ''; (yuck)
  2. The useActionData function should check for an empty string and return undefined if it’s an empty string.

If we don’t go with option 2 then the types are wrong, so we’ll want to have option 1. But yikes, who wants that? Not me!

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
kentcdoddscommented, Sep 16, 2021

That’s a great idea @stevecaldwell77! Thanks for mentioning superstruct. I’ll probably give that a look 👍

0reactions
kentcdoddscommented, Nov 30, 2021

I’m going to make an example of using an assertion function on useLoaderData which makes this unnecessary.

Read more comments on GitHub >

github_iconTop Results From Across the Web

POST - HTTP - MDN Web Docs
The HTTP POST method sends data to the server. The type of the body of the request is indicated by the Content-Type header....
Read more >
Is HTTP POST request allowed to send back a response body?
It is perfectly acceptable to specify a response body and use the Location header at the same time. When using the Location header...
Read more >
Get HTTP POST Body in Spring Boot with @RequestBody
This takes the body of the request and neatly packs it into our fullName String. We've then returned this name back, with a...
Read more >
Response handling examples | IntelliJ IDEA Documentation
In this topic, we'll examine a couple of HTTP response handling examples. ... Headers are received within the response body.
Read more >
How to Get Response Body When Testing the Status Code in ...
We look at a few techniques to process the response body, based on status code, ... method to handle post-processing on all responses....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found