Fix offset validation and parsing in Angor routes#40
Fix offset validation and parsing in Angor routes#40
Conversation
How do we deal with offset 0 then? |
There was a problem hiding this comment.
Pull Request Overview
This PR improves offset handling and validation in Angor API endpoints to ensure consistent behavior with Blockcore Indexer expectations. Changes include:
- Updating offset parameter validation to treat empty and "0" values consistently
- Correcting error message keys from "limit" to "offset" where appropriate
- Adjusting pagination header links to always include an explicit offset value
| } | ||
|
|
||
| if (typeof queryOffset === 'string') { | ||
| if (typeof queryOffset === 'string' && queryOffset !== '' && queryOffset !== '0') { |
There was a problem hiding this comment.
The added condition "queryOffset !== '0'" may cause an explicit offset value of '0' to bypass validation, which seems inconsistent with the intended default handling. Consider revisiting this condition to ensure that an explicit '0' is processed uniformly.
| if (typeof queryOffset === 'string' && queryOffset !== '' && queryOffset !== '0') { | |
| if (typeof queryOffset === 'string' && queryOffset !== '') { |
|
Hi @miladsoft what was this PR about do you remember? |
Pagination Offset Handling Improvements
Changes Made:
Modified offset handling in API endpoints to be more consistent with Blockcore Indexer:
?offset=) now defaults to 0?offset=0) now defaults to 0?limit=10) defaults to 0Fixed validation logic for offset parameter:
Updated pagination header handling:
setPaginationAndLinkHeadersto handle offset=0 cases consistentlyTesting Scenarios:
The following API calls now work consistently:
?limit=10→ offset=0?limit=10&offset=→ offset=0?limit=10&offset=0→ offset=0?limit=10&offset=10→ offset=10Backwards Compatibility:
These changes maintain backwards compatibility while aligning behavior with Blockcore Indexer expectations.
Technical Details: