Skip to content

Commit 4c2abb6

Browse files
author
Olivier Bonnaure
committed
refactor: improve errors catch
1 parent 4d2e91e commit 4c2abb6

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

.init.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ local db_config = DecodeJson(LoadAsset("config/database.json"))
1616
InitDB(db_config)
1717

1818
Views = {}
19+
isApi = false
1920

2021
-- LastModifiedAt is used to cache the last modified time of the assets
2122
-- so that we can use it to send the correct last modified time to the client

.lua/luaonbeans.lua

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Surreal = {}
88

99
function LoadViewsRecursively(path)
1010
local dir = unix.opendir(path)
11+
assert(dir ~= nil, "Error while opening path " .. path)
1112

1213
while true do
1314
local file, kind = dir:read()
@@ -26,8 +27,6 @@ function LoadViewsRecursively(path)
2627

2728
end
2829
dir:close()
29-
30-
return layouts
3130
end
3231

3332
function Page(view, layout, bindVarsView, bindVarsLayout)
@@ -263,17 +262,17 @@ function HandleRequest()
263262

264263

265264
if GetPath() == "/" then
266-
path = {
265+
local default_routes = {
267266
["GET"] = "/index",
268267
["POST"] = "/create",
269268
["PUT"] = "/update",
270269
["PATCH"] = "/update",
271270
["DELETE"] = "/delete"
272271
}
273-
path = path[GetMethod()]
272+
path = default_routes[GetMethod()]
274273
end
275274

276-
local aql_page = false
275+
local aql_page = nil
277276
if not string.match(path, "%.") then -- check only if there is no extension
278277
aql_page = LoadAsset("aqlpages/" .. path .. ".aql")
279278
end
@@ -323,6 +322,8 @@ end
323322
function WriteJSON(object)
324323
SetHeader("Content-Type", "application/json; charset=utf-8")
325324
local json = EncodeJson(object)
325+
assert(json ~= nil, "Object is not serializable")
326+
326327
local etag = EncodeBase64(Md5(json))
327328

328329
if etag == GetHeader("If-None-Match") then
@@ -391,6 +392,8 @@ end
391392

392393
function LoadPublicAssetsRecursively(path)
393394
local dir = unix.opendir(path)
395+
assert(dir ~= nil, "Error while opening path " .. path)
396+
394397
while true do
395398
local file, kind = dir:read()
396399
if file == nil then break end
@@ -445,6 +448,7 @@ function LoadCronsJobs(path)
445448
if os.date("%S") == "00" then -- run every minute
446449
path = path or "app/cronjobs"
447450
local dir = unix.opendir(path)
451+
assert(dir ~= nil, "Error while opening path " .. path)
448452

449453
while true do
450454
local file, kind = dir:read()

0 commit comments

Comments
 (0)