{"id":21548585,"url":"https://github.com/technion/fetch_with_checks","last_synced_at":"2025-03-18T02:15:56.583Z","repository":{"id":145343766,"uuid":"431796206","full_name":"technion/fetch_with_checks","owner":"technion","description":null,"archived":false,"fork":false,"pushed_at":"2021-12-18T08:16:54.000Z","size":83,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-01-24T09:29:25.793Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/technion.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-11-25T10:03:20.000Z","updated_at":"2021-12-18T08:16:57.000Z","dependencies_parsed_at":null,"dependency_job_id":"06a121ac-09b0-4b12-9b6e-995e489bee78","html_url":"https://github.com/technion/fetch_with_checks","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/technion%2Ffetch_with_checks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/technion%2Ffetch_with_checks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/technion%2Ffetch_with_checks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/technion%2Ffetch_with_checks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/technion","download_url":"https://codeload.github.com/technion/fetch_with_checks/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244141482,"owners_count":20404837,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-24T06:19:04.813Z","updated_at":"2025-03-18T02:15:56.578Z","avatar_url":"https://github.com/technion.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# fetch_with_checks\r\n\r\nStatus: Works\r\n\r\nThe fetch spec: https://developer.mozilla.org/en-US/docs/Web/API/fetch describes ten different error modes that all throw \"TypeError\". Nine of these are coding errors and only one is \"throws a network error\". There is no defined way of telling the difference.\r\nThis function provides a wrapper to aim to detect known coding errors in advance.\r\n\r\n# Example\r\n\r\nAn example can be found in [myfetch.tsx](myfetch.tsx). This is an example module containing a React element to implement a cat facts lookup. When supplying a valid URL, the expected result is given. When a URL is invalid, the output will clearly explain why.\r\n\r\n# Error Types\r\n\r\n## URLError\r\n- URL Fails to parse as a `new URL()`, eg `fetch_with_checks(\"\\x00\")`\r\n- URL Contains a credentials, eg `fetch_with_checks(\"https://user:password@example.com/\")`\r\n- URL Contains invalid scheme, eg `fetch_with_checks(\"hxxp://example.com\")`\r\n\r\n## HeaderError\r\n\r\nAll variations of invalid headers will throw this error, examples from the API guide:\r\n```\r\n// space in \"C ontent-Type\"\r\nconst headers = {\r\n    \"C ontent-Type\": \"text/xml\",\r\n    \"Breaking-Bad\": \"\u003c3\"\r\n};\r\n\r\n\r\nconst headers = [\r\n    [\"Content-Type\", \"text/html\", \"extra\"],\r\n    [\"Accept\"],\r\n];\r\n\r\n```\r\n\r\n## ModeError\r\n- Provided mode is not from a valid list, eg `fetch_with_checks(\"https://example.com/\", { mode: \"not a mode\" })`\r\n- Mode is no-cors but method is not a cors-safe method, eg `fetch_with_checks(\"https://example.com/\", { mode: \"no-cors\", method: 'CONNECT' })`\r\n\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftechnion%2Ffetch_with_checks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftechnion%2Ffetch_with_checks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftechnion%2Ffetch_with_checks/lists"}