Skip to content

switch to http client for pushover notifier#1490

Merged
crazy-max merged 1 commit intomasterfrom
pushover-http
Aug 31, 2025
Merged

switch to http client for pushover notifier#1490
crazy-max merged 1 commit intomasterfrom
pushover-http

Conversation

@crazy-max
Copy link
Owner

@crazy-max crazy-max marked this pull request as ready for review August 31, 2025 13:45
@crazy-max crazy-max merged commit c14b41e into master Aug 31, 2025
43 checks passed
@crazy-max crazy-max deleted the pushover-http branch August 31, 2025 13:49
req.Header.Set("User-Agent", c.meta.UserAgent)

resp, err := hc.Do(req)
if err != nil {
Copy link

@DrEsteban DrEsteban Sep 1, 2025

Choose a reason for hiding this comment

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

@crazy-max why not check the status code of the response here? According to the docs, a non-200 response code will not generate an error. If the user entered incorrect credentials and you get a 401/403 here, for example, there's an opportunity to provide a much better error message.

Copy link

@DrEsteban DrEsteban Sep 1, 2025

Choose a reason for hiding this comment

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

You only ever consume/log the StatusCode in case of a failure to parse JSON, which may not fail in the case of non-success responses because the error body might be JSON formatted. This may lead to very confusing behavior for the user to diagnose.

Token string `json:"token"`
}

if err = json.NewDecoder(resp.Body).Decode(&respBody); err != nil {
Copy link

@DrEsteban DrEsteban Sep 1, 2025

Choose a reason for hiding this comment

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

Suggest logging the full unparsed response body (e.g. as a string) when debug logging turned on. As well as basic HTTP stuff like status code.

Copy link
Owner Author

Choose a reason for hiding this comment

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

It is next line if unmarshal fails:

return errors.Wrapf(err, "cannot decode JSON body response for HTTP %d %s status: %+v", resp.StatusCode, http.StatusText(resp.StatusCode), respBody)

Choose a reason for hiding this comment

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

Oh yeah I meant unconditionally log it! Not just on failure to parse as JSON.

I'm not sure if that's a convention you follow, but I find it useful to have those sorts of things in verbose logs for providing more context when diagnosing issues -- even if the call is successful. That's what the Debug log is for, IMO 🙂

Choose a reason for hiding this comment

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

And actually... On a second look, I'm not sure the existing log statement will work as intended. It's trying to serialize the struct, which won't be populated since JSON deserialization failed. I think you need to read the body as a string and log that instead.

appReset = time.Unix(int64(i), 0)
}
}
log.Debug().Msgf("Pushover app limit: %d, remaining: %d, reset: %s", appLimit, appRemaining, appReset)
Copy link

@DrEsteban DrEsteban Sep 1, 2025

Choose a reason for hiding this comment

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

You don't want to return early with an error here? Don't we already know the POST failed due to rate limiting if we get here? Won't this run the risk of the app assuming the POST was successful and recording it as such in the DB, when in reality it never went through?

I think ideally there'd be some mechanism to automatically retry the request later after appReset has elapsed. (And possibly start queuing other requests since we know they will fail until the limit is renewed.) But at the very least it should return an error so higher level code paths don't assume the post was successful.

Having that many images need an update at the same time, such that the rate limit is exhausted, might be somewhat of an edge case or only a first-run concern... But IMO it just speaks to the reliability & "completeness" of the Pushover integration!

Copy link

@DrEsteban DrEsteban Sep 1, 2025

Choose a reason for hiding this comment

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

Ah forgive me, I misread this if block. This is just gathering the information, which might be there even on successful calls.

I guess the sort of thing I described above would need to live in an if checking for StatusCode == 429.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Yes didn't want yet to bail out if rate-limiting detected but we could as follow-up. Just wanted to log it first.

form.Add("url_title", c.meta.Name)
}
form.Add("timestamp", strconv.FormatInt(time.Now().Unix(), 10))
form.Add("html", "1")

Choose a reason for hiding this comment

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

Might make sense to log the request body under Debug. (Maybe with token sanitized?)

Copy link
Owner Author

Choose a reason for hiding this comment

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

Yes I think we could

@DrEsteban
Copy link

Good call rolling your own Pushover client! 🧠 Definitely seems to make sense here since it's not too complex and gives you much finer control.

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.

2 participants