From 83b3811266ba66ab96b58ae7885b4b949385a54f Mon Sep 17 00:00:00 2001 From: Pierce Lally Date: Sun, 1 Oct 2023 13:44:25 -0400 Subject: [PATCH] Http error code handling for PlayURL (#45) * give bass errors for 401, 403, and 404 status codes * remove debug print * remove default code value --- lua/cfc_http_restrictions/shared/filetypes.lua | 4 ++-- lua/cfc_http_restrictions/wraps/playURL.lua | 12 ++++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lua/cfc_http_restrictions/shared/filetypes.lua b/lua/cfc_http_restrictions/shared/filetypes.lua index 03af135..02466ef 100644 --- a/lua/cfc_http_restrictions/shared/filetypes.lua +++ b/lua/cfc_http_restrictions/shared/filetypes.lua @@ -18,11 +18,11 @@ function CFCHTTP.getFileType( data ) end ---@param url string ----@param callback fun( urls: string[], err: string|nil) +---@param callback fun( urls: string[], err: string|nil, code ) function CFCHTTP.GetFileDataURLS( url, callback ) http.Fetch( url, function( body, _, _, code ) if code < 200 or code > 299 then - callback( {}, "HTTP request returned status code " .. code ) + callback( {}, "HTTP request returned status code " .. code, code ) return end diff --git a/lua/cfc_http_restrictions/wraps/playURL.lua b/lua/cfc_http_restrictions/wraps/playURL.lua index 85d33d1..f79a23e 100644 --- a/lua/cfc_http_restrictions/wraps/playURL.lua +++ b/lua/cfc_http_restrictions/wraps/playURL.lua @@ -31,13 +31,21 @@ local function wrapPlayURL() return end - CFCHTTP.GetFileDataURLS( url, function( uris, err ) + CFCHTTP.GetFileDataURLS( url, function( uris, err, code ) if err ~= nil then logData.urls[1].status = "blocked" logData.urls[1].reason = err CFCHTTP.LogRequest( logData ) - if callback then callback( nil, CFCHTTP.BASS_ERROR_BLOCKED_CONTENT, "BASS_ERROR_BLOCKED_CONTENT" ) end + if callback then + if code == 401 or code == 403 then + callback( nil, 49, "BASS_ERROR_DENIED" ) + elseif code == 404 then + callback( nil, 2, "BASS_ERROR_FILEOPEN" ) + else + callback( nil, CFCHTTP.BASS_ERROR_BLOCKED_CONTENT, "BASS_ERROR_BLOCKED_CONTENT" ) + end + end return end if #uris == 0 then