Removed Exceptions & unused components

This commit is contained in:
Marcel Lorbeer 2023-07-25 16:56:14 +02:00
parent 6033e8fc14
commit 7fb36d47df
3 changed files with 4 additions and 9 deletions

View File

@ -1,4 +1,3 @@
local HttpService = game:GetService("HttpService")
local Utils = require(script.Parent.Parent.Utils)
local Entry = require(script.Parent.Entry)
@ -59,8 +58,7 @@ Collection.drop = function(self:typeof(Collection))
if not self._collectionName then error("[MarcSync: Collection] Invalid Object created or trying to access an destroied object.") end
local result = Utils.makeHTTPRequest("collection", "DELETE", "https://api.marcsync.dev/v0/collection/"..self._collectionName, {}, self._accessToken);
if not result["success"] then error(result["errorMessage"]) end
self._collectionName = nil
self._accessToken = nil
self = nil
end
return {

View File

@ -16,7 +16,7 @@ Entry.getValues = function(self:typeof(Entry)):typeof(types.EntryData)
end
Entry.updateValues = function(self:typeof(Entry), values:typeof(types.EntryData)):number
local result = Utils.makeHTTPRequest("entryId", "PUT", "https://api.marcsync.dev/v0/entries/"..self._tableId, {["filters"]={["_id"]=self._objectId},["data"]=values}, self._accessToken);
local result = Utils.makeHTTPRequest("entry", "PUT", "https://api.marcsync.dev/v0/entries/"..self._tableId, {["filters"]={["_id"]=self._objectId},["data"]=values}, self._accessToken);
if result["success"] and result["modifiedEntries"] and result["modifiedEntries"] > 0 then
for i,v in pairs(values) do
@ -31,7 +31,7 @@ end
Entry.delete = function(self:typeof(Entry))
if typeof(self) ~= "table" then error("Please use : instead of .") end
local result = Utils.makeHTTPRequest("entryId", "DELETE", "https://api.marcsync.dev/v0/entries/"..self._tableId, {["filters"]={["_id"]=self._objectId}}, self._accessToken);
local result = Utils.makeHTTPRequest("entry", "DELETE", "https://api.marcsync.dev/v0/entries/"..self._tableId, {["filters"]={["_id"]=self._objectId}}, self._accessToken);
if not result["success"] then error(result["errorMessage"]) end
self = nil

View File

@ -22,15 +22,13 @@ function errorHandler(type: string, resultBody: any, resultObject: {})
elseif resultObject["StatusCode"] == 400 then
Error = CollectionError.CollectionAlreadyExists("CollectionAlreadyExists")
end
elseif type == "entry" or type == "entryId" then
elseif type == "entry" then
if resultObject["StatusCode"] == 401 then
Error = AuthorizationError.InvalidAccessToken("InvalidAccessToken")
elseif resultObject["StatusCode"] == 404 then
Error = CollectionError.CollectionNotFound("CollectionNotFound")
elseif resultObject["StatusCode"] == 400 then
Error = EntryError.InvalidEntryData("InvalidEntryData")
elseif type == "entryId" and ((resultBody["modifiedEntries"] and resultBody["modifiedEntries"] == 0) or (resultBody["deletedEntries"] and resultBody["deletedEntries"] == 0)) then
Error = EntryError.EntryNotFound("EntryNotFound")
end
end
@ -53,7 +51,6 @@ function utils.makeHTTPRequest(type: string, method: string, url: string, body:
end
end)
if success and resultBody and resultBody["success"] then
if type == "entryId" and ((resultBody["modifiedEntries"] and resultBody["modifiedEntries"] == 0) or (resultBody["deletedEntries"] and resultBody["deletedEntries"] == 0)) then return errorHandler(type, resultBody, resultObj) end
if resultBody["warning"] then warn('[MarcSync HTTPRequest Handler] MarcSync HTTP Request returned warning for URL "'..url..'" with body: "'..HttpService:JSONEncode(body)..'": '..resultBody["warning"]) end
return resultBody
end