Http error code handling for PlayURL (#45)

* give bass errors for 401, 403, and  404 status codes

* remove debug print

* remove default code value
This commit is contained in:
Pierce Lally 2023-10-01 13:44:25 -04:00 committed by GitHub
parent 18b9e2f35f
commit 83b3811266
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 4 deletions

View File

@ -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

View File

@ -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