Bialu-Software / openpress

✨Fully open-source and customizable blog
https://openpress.bialu.fun/
MIT License
4 stars 2 forks source link

Add error handling to the routes #21

Open gumernus opened 1 year ago

gumernus commented 1 year ago
D:\programing\Bialu\developer-blog\node_modules\sequelize\lib\dialects\abstract\query-generator.js:1743
      throw new Error(`WHERE parameter "${key}" has invalid "undefined" value`);
            ^

Error: WHERE parameter "username" has invalid "undefined" value
    at SQLiteQueryGenerator.whereItemQuery (D:\programing\Bialu\developer-blog\node_modules\sequelize\lib\dialects\abstract\query-generator.js:1743:13)
    at D:\programing\Bialu\developer-blog\node_modules\sequelize\lib\dialects\abstract\query-generator.js:1734:25
    at Array.forEach (<anonymous>)
    at SQLiteQueryGenerator.whereItemsQuery (D:\programing\Bialu\developer-blog\node_modules\sequelize\lib\dialects\abstract\query-generator.js:1732:35)
    at SQLiteQueryGenerator.getWhereConditions (D:\programing\Bialu\developer-blog\node_modules\sequelize\lib\dialects\abstract\query-generator.js:2075:19)
    at SQLiteQueryGenerator.selectQuery (D:\programing\Bialu\developer-blog\node_modules\sequelize\lib\dialects\abstract\query-generator.js:988:28)
    at SQLiteQueryInterface.select (D:\programing\Bialu\developer-blog\node_modules\sequelize\lib\dialects\abstract\query-interface.js:407:59)
    at user.findAll (D:\programing\Bialu\developer-blog\node_modules\sequelize\lib\model.js:1140:47)
    at async user.findOne (D:\programing\Bialu\developer-blog\node_modules\sequelize\lib\model.js:1240:12)
    at async User.fetch_by_username (D:\programing\Bialu\developer-blog\backend\helper.js:19:18)

Node.js v18.4.0

when running curl -X POST -d "username=your_username&password=your_password" http://localhost:3000/api/login. The user doesn't exist.

HyScript7 commented 1 year ago

Can you link me to the commit where the code which produced this issue is?

gumernus commented 1 year ago

one of these https://github.com/orgs/Bialu-Software/projects/5/views/1?filterQuery=&pane=issue&itemId=38283181

gumernus commented 1 year ago

just tried /getPosts without a body and this happened: image @HyScript7

gumernus commented 1 year ago

we need the error handling 😭 (the filter should not be required i guess)

gumernus commented 1 year ago

it runs perfectly fine with body:

{
  "filters": {}
}
gumernus commented 1 year ago

it runs perfectly fine with body:

{
  "filters": {}
}

okay i have fixed this in the routes but the error handling still needs to be done in the helper

HyScript7 commented 1 year ago

Since I am not responsible for that part of the CRUD, I don't really know how to fix that, but since putting an empty filter works, I suppose setting the filter's default value to {} should fix this. Edit: I haven't accounted for undefined to be passed in the arguments, except for the post's update function, where we take advantage of undefined values.

gumernus commented 1 year ago

Since I am not responsible for that part of the CRUD, I don't really know how to fix that, but since putting an empty filter works, I suppose setting the filter's default value to {} should fix this. Edit: I haven't accounted for undefined to be passed in the arguments, except for the post's update function, where we take advantage of undefined values.

well i have fixed it with this monster

let filters;

if (req.body.filters === undefined) { filters = { headline: "" } }
else if (typeof req.body.filters == "object") { filters = Object.keys(req.body.filters).length == 0 ? { headline: "" } : req.body.filters }