Skip to content

Commit

Permalink
Change the URL exists logic to return false only when it's 404
Browse files Browse the repository at this point in the history
  • Loading branch information
DilwoarH committed Dec 12, 2024
1 parent 38cdfec commit 8b1ba74
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/controllers/submitUrlController.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,9 @@ class SubmitUrlController extends UploadController {
if (!response) {
return false
}

try {
return (response.status >= 200 && response.status < 300) || response.status === 400 // need to add 400 as some servers return 400 for head requests
return response.status !== 404 // Allow everything except 404, we cannot be sure what the server will return for HEAD requests
} catch (err) {
logger.warn(err)
return true
Expand Down
4 changes: 2 additions & 2 deletions test/unit/submitUrlController.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ describe('SubmitUrlController', async () => {
expect(SubmitUrlController.isUrlAccessible({ status: 200 })).toBe(true)
})

it('should return false for URLs that exist with a 3XX status code', async () => {
expect(SubmitUrlController.isUrlAccessible({ status: 301 })).toBe(false)
it('should return true for URLs that exist with a 3XX status code', async () => {
expect(SubmitUrlController.isUrlAccessible({ status: 301 })).toBe(true)
})

it('should return false for URLs that exist with a 4XX status code', async () => {
Expand Down

0 comments on commit 8b1ba74

Please sign in to comment.