mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-04-22 21:55:15 +00:00
Adjust logging and error handling in the client
* HTTP responses in the error range (400+) now properly turn into errors * ROJO_EPIPHANY_DEV_CREATE now creates more verbose configuration * Default configuration values are now much more explicit * Errors that cause session termination are labeled more clearly.
This commit is contained in:
@@ -11,6 +11,14 @@ ApiContext.__index = ApiContext
|
|||||||
-- TODO: Audit cases of errors and create enum values for each of them.
|
-- TODO: Audit cases of errors and create enum values for each of them.
|
||||||
ApiContext.Error = {
|
ApiContext.Error = {
|
||||||
ServerIdMismatch = "ServerIdMismatch",
|
ServerIdMismatch = "ServerIdMismatch",
|
||||||
|
|
||||||
|
-- The server gave an unexpected 400-category error, which may be the
|
||||||
|
-- client's fault.
|
||||||
|
ClientError = "ClientError",
|
||||||
|
|
||||||
|
-- The server gave an unexpected 500-category error, which may be the
|
||||||
|
-- server's fault.
|
||||||
|
ServerError = "ServerError",
|
||||||
}
|
}
|
||||||
|
|
||||||
setmetatable(ApiContext.Error, {
|
setmetatable(ApiContext.Error, {
|
||||||
@@ -19,6 +27,18 @@ setmetatable(ApiContext.Error, {
|
|||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
|
local function rejectFailedRequests(response)
|
||||||
|
if response.code >= 400 then
|
||||||
|
if response.code < 500 then
|
||||||
|
return Promise.reject(ApiContext.Error.ClientError)
|
||||||
|
else
|
||||||
|
return Promise.reject(ApiContext.Error.ServerError)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return response
|
||||||
|
end
|
||||||
|
|
||||||
function ApiContext.new(baseUrl)
|
function ApiContext.new(baseUrl)
|
||||||
assert(type(baseUrl) == "string")
|
assert(type(baseUrl) == "string")
|
||||||
|
|
||||||
@@ -43,6 +63,7 @@ function ApiContext:connect()
|
|||||||
local url = ("%s/api/rojo"):format(self.baseUrl)
|
local url = ("%s/api/rojo"):format(self.baseUrl)
|
||||||
|
|
||||||
return Http.get(url)
|
return Http.get(url)
|
||||||
|
:andThen(rejectFailedRequests)
|
||||||
:andThen(function(response)
|
:andThen(function(response)
|
||||||
local body = response:json()
|
local body = response:json()
|
||||||
|
|
||||||
@@ -102,9 +123,7 @@ function ApiContext:read(ids)
|
|||||||
local url = ("%s/api/read/%s"):format(self.baseUrl, table.concat(ids, ","))
|
local url = ("%s/api/read/%s"):format(self.baseUrl, table.concat(ids, ","))
|
||||||
|
|
||||||
return Http.get(url)
|
return Http.get(url)
|
||||||
:catch(function(err)
|
:andThen(rejectFailedRequests)
|
||||||
return Promise.reject(err)
|
|
||||||
end)
|
|
||||||
:andThen(function(response)
|
:andThen(function(response)
|
||||||
local body = response:json()
|
local body = response:json()
|
||||||
|
|
||||||
@@ -129,6 +148,7 @@ function ApiContext:retrieveMessages()
|
|||||||
|
|
||||||
return Promise.reject(err)
|
return Promise.reject(err)
|
||||||
end)
|
end)
|
||||||
|
:andThen(rejectFailedRequests)
|
||||||
:andThen(function(response)
|
:andThen(function(response)
|
||||||
local body = response:json()
|
local body = response:json()
|
||||||
|
|
||||||
|
|||||||
@@ -95,8 +95,7 @@ function App:render()
|
|||||||
address = address,
|
address = address,
|
||||||
port = port,
|
port = port,
|
||||||
onError = function(message)
|
onError = function(message)
|
||||||
Logging.warn("%s", tostring(message))
|
Logging.warn("Rojo session terminated because of an error:\n%s", tostring(message))
|
||||||
Logging.trace("Session terminated due to error")
|
|
||||||
self.currentSession = nil
|
self.currentSession = nil
|
||||||
|
|
||||||
self:setState({
|
self:setState({
|
||||||
|
|||||||
@@ -1,12 +1,22 @@
|
|||||||
local Config = require(script.Parent.Config)
|
local Config = require(script.Parent.Config)
|
||||||
|
|
||||||
|
local VALUES = {
|
||||||
|
LogLevel = {
|
||||||
|
type = "IntValue",
|
||||||
|
defaultUserValue = 2,
|
||||||
|
defaultDevValue = 3,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
local CONTAINER_NAME = "RojoDevSettings" .. Config.codename
|
||||||
|
|
||||||
local function getValueContainer()
|
local function getValueContainer()
|
||||||
return game:FindFirstChild("RojoDev-" .. Config.codename)
|
return game:FindFirstChild(CONTAINER_NAME)
|
||||||
end
|
end
|
||||||
|
|
||||||
local valueContainer = getValueContainer()
|
local valueContainer = getValueContainer()
|
||||||
|
|
||||||
local function getValue(name)
|
local function getStoredValue(name)
|
||||||
if valueContainer == nil then
|
if valueContainer == nil then
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
@@ -20,7 +30,7 @@ local function getValue(name)
|
|||||||
return valueObject.Value
|
return valueObject.Value
|
||||||
end
|
end
|
||||||
|
|
||||||
local function setValue(name, kind, value)
|
local function setStoredValue(name, kind, value)
|
||||||
local object = valueContainer:FindFirstChild(name)
|
local object = valueContainer:FindFirstChild(name)
|
||||||
|
|
||||||
if object == nil then
|
if object == nil then
|
||||||
@@ -37,11 +47,13 @@ local function createAllValues()
|
|||||||
|
|
||||||
if valueContainer == nil then
|
if valueContainer == nil then
|
||||||
valueContainer = Instance.new("Folder")
|
valueContainer = Instance.new("Folder")
|
||||||
valueContainer.Name = "RojoDev-" .. Config.codename
|
valueContainer.Name = CONTAINER_NAME
|
||||||
valueContainer.Parent = game
|
valueContainer.Parent = game
|
||||||
end
|
end
|
||||||
|
|
||||||
setValue("LogLevel", "IntValue", getValue("LogLevel") or 2)
|
for name, value in pairs(VALUES) do
|
||||||
|
setStoredValue(name, value.type, value.defaultDevValue)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
_G[("ROJO_%s_DEV_CREATE"):format(Config.codename:upper())] = createAllValues
|
_G[("ROJO_%s_DEV_CREATE"):format(Config.codename:upper())] = createAllValues
|
||||||
@@ -53,7 +65,7 @@ function DevSettings:isEnabled()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function DevSettings:getLogLevel()
|
function DevSettings:getLogLevel()
|
||||||
return getValue("LogLevel")
|
return getStoredValue("LogLevel") or VALUES.LogLevel.defaultUserValue
|
||||||
end
|
end
|
||||||
|
|
||||||
return DevSettings
|
return DevSettings
|
||||||
@@ -31,4 +31,4 @@ function HttpResponse:json()
|
|||||||
return HttpService:JSONDecode(self.body)
|
return HttpService:JSONDecode(self.body)
|
||||||
end
|
end
|
||||||
|
|
||||||
return HttpResponse
|
return HttpResponse
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
local DevSettings = require(script.Parent.DevSettings)
|
local DevSettings = require(script.Parent.DevSettings)
|
||||||
|
|
||||||
local testLogLevel = nil
|
|
||||||
|
|
||||||
local Level = {
|
local Level = {
|
||||||
Error = 0,
|
Error = 0,
|
||||||
Warning = 1,
|
Warning = 1,
|
||||||
@@ -9,17 +7,14 @@ local Level = {
|
|||||||
Trace = 3,
|
Trace = 3,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
local testLogLevel = nil
|
||||||
|
|
||||||
local function getLogLevel()
|
local function getLogLevel()
|
||||||
if testLogLevel ~= nil then
|
if testLogLevel ~= nil then
|
||||||
return testLogLevel
|
return testLogLevel
|
||||||
end
|
end
|
||||||
|
|
||||||
local devValue = DevSettings:getLogLevel()
|
return DevSettings:getLogLevel()
|
||||||
if devValue ~= nil then
|
|
||||||
return devValue
|
|
||||||
end
|
|
||||||
|
|
||||||
return Level.Info
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function addTags(tag, message)
|
local function addTags(tag, message)
|
||||||
|
|||||||
Reference in New Issue
Block a user