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

♻️ Uniform naming of http status codes #5323

Merged
merged 26 commits into from
Feb 13, 2024

Conversation

pcrespov
Copy link
Member

@pcrespov pcrespov commented Feb 9, 2024

What do these changes do?

I would like to propose some basic conventions and techniques to increase robustness of error handling as well as consistency across service interfaces (regardless whether they are aiohttp or fastapi-based).

Those will be a set of simple concepts but very "noisy" changes. Therefore, I will do it in three different PRs for clarity and to encourage critics/discussion:

  1. Uniform naming of status codes (this PR)
  2. Using a base exception class per service. This base class will use pydantic's mixin extended with an automatic code hierarchical error code name.
  3. Introducing registration of exception handling for aiohttp. This approach is based on fastapi/starlette exception handling concept extended to automatically document additional responses for each entrypoint.

This first PR focuses on using a consistent naming of status codes throughout the entire codebase. Out of the many the many possible variants available:

  • 404 as a raw integer
  • aiohttp.web.HTTPNotFound.status_code
  • http.HTTPNotFound as http.HttpStatus which is an IntEnum
  • httpx.codes.NOT_FOUND as httpx.codes which is an IntEnum
  • fastapi.status.HTTP_404_NOT_FOUND as int
    I find the latter the most readable since I can easily match both number and name (not sure about you, but I always mix up codes). Moreover conversion to any of the IntEnum's above is straighforward if needed. The only inconvenient is that it requires installation of starlette. But fear no more 🦸, this PR introduces the same constants in servicelib.aiohttp.status module analogous to fastapi.status but for aiohttp-based services

Related issue/s

  • Maintenance

How to test

  • all tests in place

Dev Checklist

DevOps Checklist

None

@pcrespov pcrespov self-assigned this Feb 9, 2024
Copy link

codecov bot commented Feb 9, 2024

Codecov Report

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

Comparison is base (f834b74) 87.3% compared to head (1de6564) 87.1%.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff            @@
##           master   #5323     +/-   ##
========================================
- Coverage    87.3%   87.1%   -0.2%     
========================================
  Files        1320    1321      +1     
  Lines       54063   54152     +89     
  Branches     1172    1172             
========================================
+ Hits        47201   47219     +18     
- Misses       6612    6683     +71     
  Partials      250     250             
Flag Coverage Δ
integrationtests 63.7% <58.0%> (-1.3%) ⬇️
unittests 85.2% <88.4%> (+<0.1%) ⬆️

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

Files Coverage Δ
...e-library/src/servicelib/aiohttp/client_session.py 100.0% <ø> (ø)
...c/servicelib/aiohttp/long_running_tasks/_server.py 90.1% <100.0%> (+0.1%) ⬆️
...rary/src/servicelib/aiohttp/requests_validation.py 86.5% <100.0%> (+0.2%) ⬆️
...e-library/src/servicelib/aiohttp/rest_responses.py 91.3% <100.0%> (+0.1%) ⬆️
...s/service-library/src/servicelib/aiohttp/status.py 100.0% <100.0%> (ø)
.../service-library/src/servicelib/archiving_utils.py 82.0% <100.0%> (ø)
.../service-library/src/servicelib/background_task.py 97.9% <100.0%> (ø)
...es/service-library/src/servicelib/logging_utils.py 72.7% <ø> (ø)
...ges/service-library/src/servicelib/progress_bar.py 97.8% <100.0%> (ø)
packages/service-library/src/servicelib/redis.py 94.1% <100.0%> (ø)
... and 27 more

... and 9 files with indirect coverage changes

@pcrespov pcrespov force-pushed the maintenance/e2e-master branch from 27142de to 410ad70 Compare February 11, 2024 20:24
@pcrespov pcrespov added the t:maintenance Some planned maintenance work label Feb 11, 2024
@pcrespov pcrespov changed the title WIP: ♻️ Maintenance/e2e master ♻️ Uniform http status codes naming Feb 12, 2024
@pcrespov pcrespov added this to the Schoggilebe milestone Feb 12, 2024
@pcrespov pcrespov marked this pull request as ready for review February 12, 2024 07:19
@pcrespov pcrespov requested a review from wvangeit February 12, 2024 07:19
@pcrespov pcrespov changed the title ♻️ Uniform http status codes naming ♻️ Uniform naming of http status codes Feb 12, 2024
@pcrespov pcrespov enabled auto-merge (squash) February 12, 2024 07:47
Copy link
Contributor

@bisgaard-itis bisgaard-itis left a comment

Choose a reason for hiding this comment

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

Very cool. Thanks a lot!

@pcrespov pcrespov force-pushed the maintenance/e2e-master branch 2 times, most recently from fc7c062 to c2cb026 Compare February 12, 2024 08:39
Copy link
Contributor

@GitHK GitHK left a comment

Choose a reason for hiding this comment

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

🎉 very nice!

@pcrespov pcrespov force-pushed the maintenance/e2e-master branch from 5966eed to 1e577fa Compare February 13, 2024 08:29
@pcrespov pcrespov force-pushed the maintenance/e2e-master branch from 1e577fa to 09be066 Compare February 13, 2024 08:29
Copy link

Quality Gate Passed Quality Gate passed

Issues
0 New issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

@pcrespov pcrespov merged commit 194c626 into ITISFoundation:master Feb 13, 2024
54 checks passed
jsaq007 pushed a commit to jsaq007/osparc-simcore that referenced this pull request Feb 22, 2024
@pcrespov pcrespov deleted the maintenance/e2e-master branch March 5, 2024 13:24
@pcrespov pcrespov mentioned this pull request Mar 13, 2024
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
t:maintenance Some planned maintenance work
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants