Genie Discord forum

Author Avatarnikolaich
11/20/2023, 4:33:00 PM

I have no idea what this means. It only happens when i'm in specific route, any ideas?

Error: 2023-11-20 19:29:13 ArgumentError: invalid base 10 digit 'P' in "Product 2"
Error: 2023-11-20 19:27:03 ArgumentError: invalid base 10 digit 'Н' in "НОЖНИЦЫ"

The thing is that data is still loaded from the database and passes into my templates, and it renders them. But it seems like no css is being loaded.

Author AvatarPere
11/20/2023, 4:51:30 PM

can you share your route definition? it looks like you've define the parameter as an integer but are passing a string instead

Author Avatarnikolaich
11/20/2023, 4:58:44 PM
route("/products/:id") do 
  product_id = parse(Int64,payload(:id))
  @info product_id
  product_result = Products.get_product(product_id)
  @info product_result
  page = open(io->read(io, String),"./public/product.jl.html")
  Html.html(page,product = product_result)
Author Avatarnikolaich
11/20/2023, 4:59:13 PM

I specifically display this in console so that this could never happen

Author Avatarnikolaich
11/20/2023, 4:59:23 PM

yet this does happen for some reason

Author Avatarnikolaich
11/22/2023, 2:39:00 AM

okay i think i understood what you meant but i can't possibly know how id can become something else, given that i dont take it by id, but rather by a symbol

Author Avatarnikolaich
11/22/2023, 2:39:17 AM

like not by 1 but by (:id)

Author AvatarPere
11/22/2023, 7:33:35 PM

in this line product_id = parse(Int64,payload(:id)) payload(:id) will be whatever you have after /products/ in the URL. Hence, i it's not an integer then calling parsethrows an error

Try to display the value of idin the REPL with @show and you'll see why it's not working.

In case you've not seen it, we have a guide on building APIs

Author Avatarnikolaich
11/24/2023, 10:54:25 PM

Well i'm trying to test this, yet i just can't find anything wrong with what i'm doing. Maybe this is a parse error? Maybe you can't parse substrings?

Author AvatarPere
11/27/2023, 9:16:54 AM

Why don't you set the type right in the URL like in the example I shared? That way an exception will be thrown if you pass anything other than an integer. This is the syntax:

route("/api/numbers/:N::Int", API.numbers)