EricqyHan / MVC-R1-F3-T1-V2

1 stars 1 forks source link

TypeError on login #12

Open Necroni opened 2 years ago

Necroni commented 2 years ago

Error produced on login. User does have an item in the wishlist that has price listed as a non-number - that's my first guess as to a solution. This means we'd want to sanitize data such that only numbers can be input in the wish form, maybe?

Error reads: TypeError: /mnt/d/Greg/Learning/Learn With Leon/teamproject/MVC-R1-F3-T1-V2/views/wishlist.ejs:29 27|

  • 28|

    <%=e.wish%>

    29| Cost: $<%=e.price.toFixed(2)%> 30| Link To Item 31| Delete 32|

  • Cannot read properties of undefined (reading 'toFixed') at eval (eval at compile (/mnt/d/Greg/Learning/Learn With Leon/teamproject/MVC-R1-F3-T1-V2/node_modules/ejs/lib/ejs.js:673:12), :23:33) at Array.forEach () at eval (eval at compile (/mnt/d/Greg/Learning/Learn With Leon/teamproject/MVC-R1-F3-T1-V2/node_modules/ejs/lib/ejs.js:673:12), :12:15) at wishlist (/mnt/d/Greg/Learning/Learn With Leon/teamproject/MVC-R1-F3-T1-V2/node_modules/ejs/lib/ejs.js:703:17) at tryHandleCache (/mnt/d/Greg/Learning/Learn With Leon/teamproject/MVC-R1-F3-T1-V2/node_modules/ejs/lib/ejs.js:274:36) at View.exports.renderFile [as engine] (/mnt/d/Greg/Learning/Learn With Leon/teamproject/MVC-R1-F3-T1-V2/node_modules/ejs/lib/ejs.js:491:10) at View.render (/mnt/d/Greg/Learning/Learn With Leon/teamproject/MVC-R1-F3-T1-V2/node_modules/express/lib/view.js:135:8) at tryRender (/mnt/d/Greg/Learning/Learn With Leon/teamproject/MVC-R1-F3-T1-V2/node_modules/express/lib/application.js:640:10) at Function.render (/mnt/d/Greg/Learning/Learn With Leon/teamproject/MVC-R1-F3-T1-V2/node_modules/express/lib/application.js:592:3) at ServerResponse.render (/mnt/d/Greg/Learning/Learn With Leon/teamproject/MVC-R1-F3-T1-V2/node_modules/express/lib/response.js:1012:7) at ServerResponse.res.render (/mnt/d/Greg/Learning/Learn With Leon/teamproject/MVC-R1-F3-T1-V2/node_modules/express-flash/lib/express-flash.js:29:16) at getWishes (/mnt/d/Greg/Learning/Learn With Leon/teamproject/MVC-R1-F3-T1-V2/controllers/wishes.js:7:17) at processTicksAndRejections (node:internal/process/task_queues:96:5)

    Necroni commented 2 years ago

    This error ONLY seems to exist if there is a wishlist item with a "price" attribute that is not a number. For example, if price: "$222" exists in a collection, this will break the login.

    Since we've now added number validation to the input (and therefore can't be repeated without directly editing the database), this issue should take a back seat to other more pressing issues.

    Possible future solution is to add a new ensureNumber function into the middleware, so that the client checks whether the input is a number before attempting to submit to the database.