Skip to content

Conversation

@my-name-is-lad
Copy link
Contributor

No description provided.

@my-name-is-lad my-name-is-lad requested a review from Yuras April 1, 2025 18:11
Comment on lines +10 to +11
- git: https://github.com/typeable/req.git
commit: 8829ac5197f7a4b3f04b7fdfc3ea66cfe70ab0a5
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding yet another fork into our collection just to add response logging looks fishy. Are we sure there high chances to propagate this change upstream?

Why not to use, e.g. LbsResponse?

do
  resp <- reqCb POST (url https) jbody lbsResponse auth (logRequest obj)
  logResponse resp
  case Aeson.eitherDecode resp of
    ... 

Won't that work?

Copy link
Contributor Author

@my-name-is-lad my-name-is-lad Apr 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only in case of success. Any status code outside of [200;300) range throws an exception and logging that is much trickier, hence this. I tried to work around this without the fork, but it's just not worth it.

Also, I submitted a PR (mrkkrp/req#184) and the upstream seems active enough.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should just overwrite httpConfigCheckResponse. The default one indeed fails on 4XX statuses

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So it is like

-- Modify 'httpConfigCheckResponse' to do nothing
resp <- reqCb POST (url https) jbody lbsResponse auth (logRequest obj)
logResponse resp
if
  | isOk resp.statusCode -> Aeson.decode resp
  | ...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be too much work to drop req in favor to http-client at this point, right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got your point. Thought there are some other issues with it not mentioned.
I agree that it would be nice to do a replacement. I would also on the way solve the problem with logger context. We can mostly copy-paste what we do in NDC packages.
So do we want to invest time into the replacement? I can take it in case of

Copy link
Contributor Author

@my-name-is-lad my-name-is-lad Apr 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw logResponse callback looks too ad hoc. If to go that way then it should be something a la https://hackage.haskell.org/package/http-client-0.7.17/docs/Network-HTTP-Client.html#v:managerModifyResponse.

The problem with this is that the response could be potentially huge. Currently, logResponse only sees a preview (first 1024 bytes by default), which should be enough for our needs here. But if say the response is a multi-gigabyte file, this would be tricky to do correctly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, logResponse only sees a preview (first 1024 bytes by default), which should be enough for our needs here.

Zzz... Are we sure all Connexpay responses fit into 1024 bytes?

That's why managerModifyResponse is built around BodyReader and it is an obligation of library user to care about response size.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Zzz... Are we sure all Connexpay responses fit into 1024 bytes?

so far they did, but we can increase that easily.

That's why managerModifyResponse is built around BodyReader and it is an obligation of library user to care about response size.

True. We can also use this here, if we want. But I agree, it's a good idea to add a similar feature to req.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, logResponse only sees a preview (first 1024 bytes by default), which should be enough for our needs here.

If bad things may happen they will 🤷‍♂️
Got biten by this. In the task where we need to see information not fit into 1024 bytes. Costed me time trying to find out addressVerificationCode in the logs until I remembered about this thread

@my-name-is-lad my-name-is-lad merged commit 1e820f2 into master Apr 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants