Parse query parameter to number?
Answered
Southern rough shrimp posted this in #help-forum
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
Southern rough shrimpOP
Is there a way of only accepting query params of type number? i.e removing the manual parsing from string to integer?
![Image](https://cdn.discordapp.com/attachments/1193608813782249472/1193608814113591306/image.png?ex=65ad55d5&is=659ae0d5&hm=c7ecdc212251f68182c5c6ef12af4673f53b86f0c903ff01fe6be854cf34683e&)
Answered by B33fb0n3
you can try catch the number. If it's not an number throw an error @Southern rough shrimp
10 Replies
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
Southern rough shrimpOP
in an ideal world, I could define the params as such (removing use of Number.parseInt
![Image](https://cdn.discordapp.com/attachments/1193608813782249472/1193609001267625984/image.png?ex=65ad5602&is=659ae102&hm=5510badf64a358fb344e389f356ef4f16b10ad065b9447854a6a88648c5477d4&)
![Avatar](https://cdn.discordapp.com/avatars/301376057326567425/788b75eb8862277af3d31d317ada783f.webp?size=256)
B33fb0n3
you can try catch the number. If it's not an number throw an error @Southern rough shrimp
Answer
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
Southern rough shrimpOP
Yea but my idea is to not have to do that
cleaner code
![Avatar](https://cdn.discordapp.com/avatars/301376057326567425/788b75eb8862277af3d31d317ada783f.webp?size=256)
B33fb0n3
of course it would be a more cleaner code, but you also want to check the params. And the url is a string. In every case. So handle it as a string or try catch the number 🙂
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
Southern rough shrimpOP
I may just change the id to string in the database so none of this number stuff is required
thanks for the help
![Avatar](https://cdn.discordapp.com/avatars/301376057326567425/788b75eb8862277af3d31d317ada783f.webp?size=256)
B33fb0n3
yea... please mark solution
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
Southern rough shrimpOP
![Image](https://cdn.discordapp.com/attachments/1193608813782249472/1193630927893581914/image.png?ex=65ad6a6d&is=659af56d&hm=21d1930bc2f09b8e9d61965bfd4274d08a73e55656fff4c8a05aa47daaef78a0&)
![Avatar](https://cdn.discordapp.com/avatars/301376057326567425/788b75eb8862277af3d31d317ada783f.webp?size=256)
B33fb0n3
&752637460550385834 ?