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
I've been rescuing errors and I've noticed something I don't fully understand. I don't believe it's a bug, so I'm hoping to just get some help understanding why Faraday appears to behave this way.
This is a Rails 7 app, using Faraday 2.14.0
If I send a POST request and it returns a 4xx or 5xx, I can rescue Faraday::ClientError => e or rescue Faraday::ServerError => e. In my case, I want to examine the body, since the API usually returns helpful error messages.
In the POST case, I can do e.response for the headers and body and all that.
In the PUT case, I can't; e.response is nil. However, there is e.cause.response which appears to have nearly the same information as e.response in the POST case.
I believe PUT responses are not "supposed" to return bodies in almost all cases, where a POST is expected to. I suspect this is where the difference stems from.
It would obviously be more convenient if I could access the response body in the same way in both cases. I assume there's a good reason this isn't possible and I just lack some important knowledge. Could someone help me understand why this is done this way? I appreciate the insight from those who know more than I do!
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
I've been rescuing errors and I've noticed something I don't fully understand. I don't believe it's a bug, so I'm hoping to just get some help understanding why Faraday appears to behave this way.
This is a Rails 7 app, using Faraday 2.14.0
If I send a POST request and it returns a 4xx or 5xx, I can
rescue Faraday::ClientError => eorrescue Faraday::ServerError => e. In my case, I want to examine the body, since the API usually returns helpful error messages.In the POST case, I can do
e.responsefor the headers and body and all that.In the PUT case, I can't;
e.responseis nil. However, there ise.cause.responsewhich appears to have nearly the same information ase.responsein the POST case.I believe PUT responses are not "supposed" to return bodies in almost all cases, where a POST is expected to. I suspect this is where the difference stems from.
It would obviously be more convenient if I could access the response body in the same way in both cases. I assume there's a good reason this isn't possible and I just lack some important knowledge. Could someone help me understand why this is done this way? I appreciate the insight from those who know more than I do!
Beta Was this translation helpful? Give feedback.
All reactions