Skip to content

Conversation

@loadre
Copy link
Contributor

@loadre loadre commented Feb 3, 2025

closes #24

@chshersh chshersh added type: feature New feature request component: UI Issues related to changing UI labels Feb 3, 2025
@chshersh chshersh requested review from chshersh and heathhenley and removed request for heathhenley February 3, 2025 07:55
@chshersh
Copy link
Owner

chshersh commented Feb 3, 2025

@heathhenley @loadre I've added you both as collaborators.

Since we're starting to work more on this together, feel free to review PRs of each other as well. It's a nice practice 🙂
Also good for knowledge sharing about the project.

I haven't really invested a lot into making this project contributable. I'll add proper Code of Conduct and Contributing guide soon, so there'll be less uncertainty about future of this project and conflict resolution.

@chshersh
Copy link
Owner

chshersh commented Feb 3, 2025

@qexat Since you made a contribution, it now applies to you as well 😅 No pressure!

@chshersh chshersh requested a review from qexat February 3, 2025 08:07
lib/gh/client.ml Outdated
match response with
| Error (code, msg) -> Error (Curl_error { code = Curl.errno code; msg })
| Ok response -> Ok response.body)
| Ok { body; _ } ->
Copy link
Collaborator

Choose a reason for hiding this comment

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

Huh, GitHub sends an Ok response on bad credentials?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

utop # let query token query_body =
Ezcurl.post ~params:[]
~headers:[
("Authorization", "bearer " ^ token);
]
~content:(`String (Printf.sprintf "{ \"query\": %S }" query_body))
~url:"https://api.github.com/graphql" ()
;;
val query :
  string -> string -> (Ezcurl.response, Curl.curlCode * string) result = <fun>
utop # query "foo" "query { viewer { login } }";;
- : (Ezcurl_core.response, Curl.curlCode * string) result =
Ok
 {Ezcurl_core.code = 401;
  ...
  body =
   "{\n  \"message\": \"Bad credentials\",\n  \"documentation_url\": \"https://docs.github.com/graphql\",\n  \"status\": \"401\"\n}\n";
 ...}

Github API sends 401 with plain HTTP request with curl, I think this might have something to do with how Ezcurl handles responses.

Copy link
Owner

Choose a reason for hiding this comment

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

@loadre Thanks for providing the example! I didn't know this about the internals of ezcurl.

lib/gh/client.ml Outdated

type error =
| No_github_token
| Bad_credentials
Copy link
Owner

Choose a reason for hiding this comment

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

My only feedback: let's create the bad_credentials error type and put the message, documentation url and status code inside this type and decode it from JSON:

"{\"message\":\"Bad credentials\",\"documentation_url\":\"https://docs.github.com/graphql\",\"status\":\"401\"}"

And then display this information in the UI. Let's try to avoid loosing potentially useful debugging information.

Also, I'm not sure if "Bad credentials" is the only possible message. At least, if we display the message, we'll be able to learn about different error scenarios

@heathhenley
Copy link
Collaborator

Pulled it down to test, looks great with no token and with a bad token 🚀

Update fmt_error to fit more possible error messages
| Ok { body; code; _ } ->
let open Yojson.Basic in
let json = from_string body in
if Util.member "data" json <> `Null then Ok json
Copy link
Contributor Author

@loadre loadre Feb 4, 2025

Choose a reason for hiding this comment

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

This part assumes that if response.body doesn't contain data, then it must contain message and documentation_url, which I'm not sure is a good decision or not.

Edit:
Just tested with malformed GQL query, got responses in the form of {"errors": [...]}. Maybe it deserves having its own issue (later on)?

Copy link
Owner

Choose a reason for hiding this comment

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

This part assumes that if response.body doesn't contain data, then it must contain message and documentation_url, which I'm not sure is a good decision or not.

Sounds good to me. Let's stick to it for now. We can always refine later.

Just tested with malformed GQL query, got responses in the form of {"errors": [...]}. Maybe it deserves having its own issue (later on)?

Yes, please! Feel free to create a separate issue. It's a good idea to handle such errors as well.

Copy link
Owner

@chshersh chshersh left a comment

Choose a reason for hiding this comment

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

Thank you!

@chshersh chshersh merged commit fc84ee6 into chshersh:main Feb 4, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: UI Issues related to changing UI type: feature New feature request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Handle invalid GITHUB_TOKEN

4 participants