Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add status code if the body contain a code #93

Merged
merged 9 commits into from
May 7, 2024

Conversation

ricantar
Copy link
Contributor

No description provided.

Copy link
Contributor

@Olshansk Olshansk left a comment

Choose a reason for hiding this comment

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

Couple small nits.

provider/provider.go Outdated Show resolved Hide resolved
provider/provider.go Outdated Show resolved Hide resolved
@ricantar ricantar requested a review from Olshansk May 1, 2024 16:29
provider/provider.go Outdated Show resolved Hide resolved
provider/provider.go Outdated Show resolved Hide resolved
provider/provider.go Outdated Show resolved Hide resolved
return matches[1] // Return the first captured group, which should be the status code.
}
}
return "200"
Copy link
Contributor

Choose a reason for hiding this comment

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

Are you sure you want to default to a success if none of the error cases we account for are matched?

I'm thinking one of two non mutually-exclusive ideas:

  1. Add a regex check for 200 success
  2. Update the method header to func extractStatusFromResponse(response string) (statusCode string, known bool)

And default to "unknown", false as a default case signifying "def not an error" but also "relaying logic elsewhere on success`

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, we want the default to be 200 because of normal chains (which should always get back to us with 200). Even tho it's really valuable to get those 200 cases, for now everything is "unknown" because the node are getting back to us with 200 no matter what

Copy link
Contributor

Choose a reason for hiding this comment

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

Not going to block this because you're the primary user of the library so ultimately it's up to you, but I do still thinking that defaulting to success it not a good design decision. Defaulting to unknown (can be a constant in the SDK) and handling that appropriately prevents requiring "implicit knowledge" that "200" may not necessarily a "200".

[1] https://chat.openai.com/share/111342f3-0045-4e71-b24b-4e2b8822dd25

Side note: ChatGPT also suggested extracting the regex's outside of the function.

Copy link
Contributor

Choose a reason for hiding this comment

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

@adshmh Bump on this one too. Need a 3rd data point.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The regex it's already in a separate init, will be deleted later but for now can be there. But the default to unknown it's exactly what we have now and that's what we want to avoid. However since this is a temporary patch it's not really our intended design

Copy link
Contributor

Choose a reason for hiding this comment

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

Regarding unknown vs. 200 , I think it is best to have "unknown" as the default return value, and return 200 only if it is explicitly identified in the core's response. Let the user of the library decide on what unknown means.

This makes the most sense to me because it makes sure the library does not mask any key detail: actual 200 vs. unknown is an important detail.
Although it is correctly pointed out that for now everything is "unknown" because the node are getting back to us with 200 no matter what, this library should not build on this missing/incorrect behavior and further complicate matters downstream. It should instead defer this decision to the user by returning all the available data pieces, which also removes the need for knowledge on the history of the matter when reading the library's code.

Also, "temporary" solutions may stay in-place for much longer than expected for a variety of reasons, and therefore still deserve the general application of best practices IMO.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have to disagree, the default status code for an HTTP call is 200 (which means OK I got your call), unknown is not a valid status code and should not be used. Here the definition of the RC 9110.
https://httpwg.org/specs/rfc9112.html#status.line
https://httpwg.org/specs/rfc9110.html#overview.of.status.codes

A status code must have 3 digit and we have to define a default ourself in the library (i.e: GO default is 200, if you forget to set one it will be set to 200 automatically)

Copy link
Contributor

Choose a reason for hiding this comment

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

tl;dr ASSUMING we are building a long-term solution in this PR, I suggest defeaulting to 202 and having explicit checks for 200.


I did not have strong opinions about this under the assumption that it was a hack / temp / workaround in Morse, but given @ricantar messages that the same default will apply to Shannon (see the image below), will provide another argument.

Screenshot 2024-05-06 at 10 36 57 AM
  • Regarding having a 3 digist status code instead of unknown -> Agreed.
  • Regarding using 200 -> Disagreed.

After asking perplexity (see search here), I looked into 202 and 204 and believe 202 may be the most appropriate, and least misleading, from the POV of an SDK..


What is the difference between a 200 status code and a 202 status code?:

When a server returns a 200 OK status code, it means that the server has successfully processed the client’s request and is returning the requested content in the response body.

  • 202: The request went through but we don't know what happened
  • 200: Explicit SUCCESS / OK

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can agree with that, 202 it's better for a default

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Comments addressed

Olshansk
Olshansk previously approved these changes May 7, 2024
Copy link
Contributor

@Olshansk Olshansk left a comment

Choose a reason for hiding this comment

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

Great work @ricantar and I love the shape this has taken.

I left a few NITs ONLY related to comments.

PTAL and update before merging, but otherwise :shipit:

provider/provider.go Outdated Show resolved Hide resolved
provider/provider.go Outdated Show resolved Hide resolved
provider/provider.go Outdated Show resolved Hide resolved
provider/provider.go Show resolved Hide resolved
provider/provider.go Show resolved Hide resolved
@ricantar ricantar requested a review from Olshansk May 7, 2024 16:31
Copy link
Contributor

@Olshansk Olshansk left a comment

Choose a reason for hiding this comment

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

Please make sure to update the git commit message when you squash & mege.

@ricantar ricantar merged commit 8eba803 into master May 7, 2024
3 checks passed
@ricantar ricantar deleted the add-status-code-response branch May 7, 2024 23:02
ricantar added a commit that referenced this pull request May 16, 2024
* fix: add status code if the body contain a code

* feat: Include relayOutputErr
- Add relayOutputErr type
- Update test to handle new error type

* fix: pre calculate regex

Co-authored-by: Daniel Olshansky <olshansky.daniel@gmail.com>

* Optimize errorCode extraction

* update test to include the new status code behavior with 500 as default

---------

Co-authored-by: Daniel Olshansky <olshansky.daniel@gmail.com>
ricantar added a commit that referenced this pull request May 17, 2024
* fix: add status code if the body contain a code

* feat: Include relayOutputErr
- Add relayOutputErr type
- Update test to handle new error type

* fix: pre calculate regex



* Optimize errorCode extraction

* update test to include the new status code behavior with 500 as default

---------

Co-authored-by: Daniel Olshansky <olshansky.daniel@gmail.com>
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.

None yet

3 participants