osrd icon indicating copy to clipboard operation
osrd copied to clipboard

editoast: do not panic on incorrect pagination

Open woshilapin opened this issue 1 year ago • 1 comments
trafficstars

Once, I did put a page and page_size that went out of bound... and got a 500. I don't expect editoast to panic in such case, and we could reply with either an empty Vec and a 200, or more likely something like a 404 (I chose this one). Note that on the way, I also remove panic for page==0 and page_size==0 too and transformed them into a 400.

Note that I renamed and change the semantic of the existing InvalidPageSize into PageSizeTooBig (because it was actually not triggered when page_size==0) and then I created a new InvalidPageSize that actually only check for a strictly positive number.

Here is the result.

 ❯ xh 'localhost:8090/light_rolling_stock?page_size=100&page=100'
HTTP/1.1 404 Not Found
Access-Control-Allow-Origin: *
Content-Length: 214
Content-Type: application/json
Date: Fri, 25 Oct 2024 15:21:28 GMT
Vary: origin, access-control-request-method, access-control-request-headers

{
    "status": 404,
    "type": "editoast:pagination:OutOfBound",
    "context": {
        "page_size": 100,
        "total_count": 464,
        "page": 100
    },
    "message": "no more information after page 100 when page size is 100 (total number of elements is 464)"
}

woshilapin avatar Oct 25 '24 16:10 woshilapin

:warning: Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

Attention: Patch coverage is 75.00000% with 7 lines in your changes missing coverage. Please review.

Project coverage is 39.60%. Comparing base (86ad640) to head (f6b9ad5). Report is 1 commits behind head on dev.

Files with missing lines Patch % Lines
editoast/src/views/pagination.rs 74.07% 7 Missing :warning:

:exclamation: Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@             Coverage Diff              @@
##                dev    #9480      +/-   ##
============================================
- Coverage     39.60%   39.60%   -0.01%     
  Complexity     2270     2270              
============================================
  Files          1300     1300              
  Lines         99154    99169      +15     
  Branches       3282     3282              
============================================
+ Hits          39270    39273       +3     
- Misses        57951    57963      +12     
  Partials       1933     1933              
Flag Coverage Δ
core 75.07% <ø> (ø)
editoast 73.20% <75.00%> (-0.03%) :arrow_down:
front 10.23% <ø> (ø)
gateway 2.19% <ø> (ø)
osrdyne 3.29% <ø> (ø)
railjson_generator 87.49% <ø> (ø)
tests 86.71% <ø> (ø)

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

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov-commenter avatar Oct 25 '24 16:10 codecov-commenter