From 7fb36d47df261c3f40aef2566f87c312ba8ef8ee Mon Sep 17 00:00:00 2001 From: Marcel Lorbeer Date: Tue, 25 Jul 2023 16:56:14 +0200 Subject: [PATCH] Removed Exceptions & unused components --- src/MarcSync/Objects/Collection.lua | 4 +--- src/MarcSync/Objects/Entry.lua | 4 ++-- src/MarcSync/Utils.lua | 5 +---- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/MarcSync/Objects/Collection.lua b/src/MarcSync/Objects/Collection.lua index d680dbf..73c0d79 100644 --- a/src/MarcSync/Objects/Collection.lua +++ b/src/MarcSync/Objects/Collection.lua @@ -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 { diff --git a/src/MarcSync/Objects/Entry.lua b/src/MarcSync/Objects/Entry.lua index 37f7031..3756ee7 100644 --- a/src/MarcSync/Objects/Entry.lua +++ b/src/MarcSync/Objects/Entry.lua @@ -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 diff --git a/src/MarcSync/Utils.lua b/src/MarcSync/Utils.lua index 095c8e1..194e2b2 100644 --- a/src/MarcSync/Utils.lua +++ b/src/MarcSync/Utils.lua @@ -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