Skip to content
This repository was archived by the owner on Mar 8, 2025. It is now read-only.

HTTP responses#20

Draft
Hermesiss wants to merge 2 commits into
masterfrom
httpResponse
Draft

HTTP responses#20
Hermesiss wants to merge 2 commits into
masterfrom
httpResponse

Conversation

@Hermesiss
Copy link
Copy Markdown
Collaborator

You can review existing code while we are waiting for https://github.com/wakatime/wakatime/issues/181

@Hermesiss Hermesiss requested a review from vladfaust May 31, 2019 18:29
@@ -1,5 +1,7 @@
#if (UNITY_EDITOR)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

It should be on top, for beauty 🍃

var heartbeat = new Heartbeat(file, fromSave);
if ((heartbeat.time - _lastHeartbeat.time < HEARTBEAT_COOLDOWN) && !fromSave &&
if ((heartbeat.time - _lastHeartbeat.time < HEARTBEAT_COOLDOWN) && !fromSave &&
//BUG: _lastHeartbeat has no time, entity or type
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

It's a good practice to not intervent long conditionals (even multi-line) with comments, put it on top instead.

request.SendWebRequest().completed +=
operation => {
if (request.downloadHandler.text == string.Empty) {
/*if (request.downloadHandler.text == string.Empty) {
Copy link
Copy Markdown
Owner

@vladfaust vladfaust Jun 1, 2019

Choose a reason for hiding this comment

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

Should put a comment on top of the block explaining why is it commented out.

}

/// <summary>
/// Checks for status code and takes correspond actions
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Suggested change
/// Checks for status code and takes correspond actions
/// Checks for status code and then acts accordingly

@vladfaust
Copy link
Copy Markdown
Owner

I'm sorry for the delay, @Hermesiss, I'm a bit busy with messy containers security!

First of all, thanks for your time. I do appreciate your help on the project.

I guess this PR is aimed to suppress malformed Wakatime responses. That's good, I think, as it's a third-party bug and we don't want to disrupt the user experience.

A small note — it's generally bad practice to include commented out blocks of code into the master branch. We always have the history, so we could add it back once it's working as intended.

I think the HandleHttpResponseSuccess method is too burden, isn't it enough to check response.error != null and response.status in (200..300) range? And if it's out of that range, just print Got 4xx error...

@vladfaust
Copy link
Copy Markdown
Owner

I may be in some way out of understanding the real purpose of this PR. Which issue particularly does it fix? As per #13, the problem was malformed response, which is now solved.

In everyday programming (especially for such small projects as this) we should rely on third party API to work as expected most of the time, handling all errors in bulk with minimum code. This reduces the complexity and therefore improves maintainability.

In this case, expected error is 429 only, all other are unexpected and should throw. There is no need in this HandleHttpResponseSuccess method, in my opinion.

@vladfaust
Copy link
Copy Markdown
Owner

Additionally, for better communication, you should split the PRs as much as possible, as it's sometimes hard to follow their purpose. Single PR = single change (or complex overhaul).

@Hermesiss
Copy link
Copy Markdown
Collaborator Author

There are 3 important for us error codes that require special reactions: 0, 429 and 500.

While working on 429 I tried to temporally increase HEARTBEAT_COOLDOWN. I found out that the part where it's used is broken due to some undocumented API changes.

In this PR I want to move scattered data checks to one place. I took all possible codes from dev section.

@vladfaust vladfaust marked this pull request as draft August 15, 2020 21:19
@vladfaust vladfaust changed the title [WIP] Http response HTTP responses Aug 15, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants