stadust / pointercrate

Rewrite of the https://pointercrate.com backend in Rust
MIT License
78 stars 50 forks source link

Pagination endpoints cause Internal Database Error if database is empty #77

Closed stadust closed 4 months ago

stadust commented 1 year ago

Making a request such as GET /api/v1/players/ will result in 500 Internal Server Error (Code 50003) response. This is due to the code trying to determine the extremal IDs assuming that at least one non-null row is returned from the database. If the table in question is empty however, the database will return NULL, and we get ColumnDecode { index: "0", source: UnexpectedNullError }

https://github.com/stadust/pointercrate/blob/d63f42e5be36f91b7a6fe44968033189f5cb7ef9/pointercrate-demonlist/src/player/mod.rs#L82-L86

stadust commented 1 year ago

Fix would be to either return 404 or an empty response with no Links header set (we only need the min/max to determine the "first" and "last" links used for pagination)