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

Refactor API handler wrapping #7926

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

ocket8888
Copy link
Contributor

This refactors api.Handler such that the return type is a single error instead of a user-facing error, a system-facing error, and a status code. It then handles the error specially if it is an api.Errors implementation. I also updated usage accordingly throughout the two endpoint handling packages that use api.Wrap.

Essentially this reduces

code, userErr, sysErr := someCall(inf)
if userErr != nil || sysErr != nil {
    return code, userErr, sysErr
}

to

err := someCall(inf)
if err != nil {
    return err
}

and

err := tx.QueryRow("My query", args...)
if err != nil {
    return http.StatusInternalServerError, nil, err
}

to

err := tx.QueryRow("My query", args...)
if err != nil {
    return err
}

Which Traffic Control components are affected by this PR?

  • Traffic Ops

What is the best way to verify this PR?

This is just a refactor; behavior should be unchanged and the existing tests should continue to pass.

PR submission checklist

  • This PR has tests
  • This PR has documentation
  • This PR doesn't need a CHANGELOG.md entry
  • This PR DOES NOT FIX A SERIOUS SECURITY VULNERABILITY

@ocket8888 ocket8888 added Traffic Ops related to Traffic Ops low impact affects only a small portion of a CDN, and cannot itself break one tech debt rework due to choosing easy/limited solution labels Jan 23, 2024
Copy link

codecov bot commented Jan 23, 2024

Codecov Report

Attention: 267 lines in your changes are missing coverage. Please review.

Comparison is base (3d933d0) 29.09% compared to head (870c26a) 32.06%.

Files Patch % Lines
traffic_ops/traffic_ops_golang/server/servers.go 7.95% 240 Missing and 3 partials ⚠️
...traffic_ops_golang/cdnfederation/cdnfederations.go 17.24% 24 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #7926      +/-   ##
============================================
+ Coverage     29.09%   32.06%   +2.97%     
  Complexity       98       98              
============================================
  Files           605      722     +117     
  Lines         77535    82925    +5390     
  Branches         90      970     +880     
============================================
+ Hits          22558    26590    +4032     
- Misses        52894    54183    +1289     
- Partials       2083     2152      +69     
Flag Coverage Δ
golib_unit 53.85% <ø> (+<0.01%) ⬆️
grove_unit 12.02% <ø> (ø)
t3c_unit 5.88% <ø> (ø)
traffic_monitor_unit 25.47% <ø> (ø)
traffic_ops_unit 22.15% <19.81%> (+0.06%) ⬆️
traffic_portal_v2 74.37% <ø> (?)
traffic_stats_unit 10.78% <ø> (ø)
unit_tests 29.41% <19.81%> (+3.46%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
low impact affects only a small portion of a CDN, and cannot itself break one tech debt rework due to choosing easy/limited solution Traffic Ops related to Traffic Ops
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant