question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Valid response returning "TypeError: Failed to fetch"

See original GitHub issue

As requested, please see below a new issue I am having;

I’ve just grabbed master (3.0.19) and am having this exact same issue, see my Stackoverflow post here: https://stackoverflow.com/questions/45156665/swagger-ui-typeerror-failed-to-fetch-on-valid-response

In a nutshell, I’ve simply upgraded to 3.0.19 then forced a 403 error, instead of getting a 403 - forbidden, it’s returning “TypeError: Failed to fetch”.

Previous version: * @version v2.2.6

Below is my definition snippet

"host": "uk-test-api.services",
"schemes": ["https"],`

/api/v1/cards": {
	"get": {
		"tags": ["Cards"],
		"summary": "Getsalistofcardsforafirm.",
		"operationId": "Card_GetCards",
		"produces": ["application/json"],
		"parameters": [{
			"name": "includes",
			"in": "query",
			"description": "Extracardproperties",
			"required": false,
			"type": "string"
		},
		{
			"name": "lastRowVer",
			"in": "query",
			"description": "lastRowVerofpreviousrequest",
			"required": false,
			"type": "string"
		},
		{
			"name": "Authorization",
			"in": "header",
			"description": "AuthToken",
			"required": true,
			"type": "string"
		}],
		"responses": {
			"200": {
				"description": "200response",
				"schema": {
					"$ref": "#/definitions/CardListJson"
				},
				"headers": {
					"Access-Control-Allow-Origin": {
						"type": "string"
					}
				}
			},
			"400": {
				"description": "BadRequest",
				"headers": {
					"Access-Control-Allow-Origin": {
						"type": "string"
					}
				}
			},
			"401": {
				"description": "Unauthorized",
				"headers": {
					"Access-Control-Allow-Origin": {
						"type": "string"
					}
				}
			},
			"403": {
				"description": "Forbidden",
				"headers": {
					"Access-Control-Allow-Origin": {
						"type": "string"
					}
				}
			},
			"404": {
				"description": "NotFound",
				"headers": {
					"Access-Control-Allow-Origin": {
						"type": "string"
					}
				}
			},
			"429": {
				"description": "TooManyRequests",
				"headers": {
					"Access-Control-Allow-Origin": {
						"type": "string"
					}
				}
			},
			"500": {
				"description": "InternalServerError",
				"headers": {
					"Access-Control-Allow-Origin": {
						"type": "string"
					}
				}
			},
			"504": {
				"description": "504GatewayTimeout",
				"headers": {
					"Access-Control-Allow-Origin": {
						"type": "string"
					}
				}
			}
		}

Swagger page currently with the issue: https://api-swagger-uk-test.leap.services/#/

1

The URL is HTTPS: https://uk-test-api.leap.services/api/v1/cards

PS - I’ve since tested with a 401 response and get the same issue:

2

And a 400 is working as expected:

3

@shockey @webron

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:15 (7 by maintainers)

github_iconTop GitHub Comments

4reactions
bitclawcommented, May 15, 2018

FYI this error can also happen if the user selects an HTTPS scheme and on their local development environment has a self signed SSL certificate. In this case adding -K to the curl command will fix the error or also just selecting the HTTP scheme should be sufficient.

4reactions
owenconticommented, Jul 18, 2017

Hi @ShaneGMamet,

I see this error from the Fetch API in the JS console:

Fetch API cannot load https://uk-test-api.leap.services/api/v1/cards. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://api-swagger-uk-test.leap.services' is therefore not allowed access. The response had HTTP status code 401. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

I see the browser is doing an OPTIONS pre-fetch which returns the correct Access-Control-Allow-Origin header, however the actual GET request that returns the 401 does not return the Access-Control-Allow-Origin header. Are you able to update your backend to return that header for 401 (or all error responses) and try testing this again?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Swagger UI - " TypeError: Failed to fetch" on valid response
The issue is that custom authorizers do not currently support passing through headers within the response and Swagger UI needs the Access- ...
Read more >
"TypeError: Failed to fetch" for valid response - Support
I'm trying to test an api via the Tyk catalogue. The catalogue returns a “TypeError: Failed to fetch” error. If a monitor the...
Read more >
Swagger spec error - TypeError: Failed to fetch
So my api is working but anyway i try to test it through the swagger spec, i get the error: TypeError: Failed to...
Read more >
typeerror: failed to fetch swagger - You.com | The AI Search ...
After a day of troubleshooting and the Swagger support guys pointing me in the right direction, it turns out that this is currently...
Read more >
Swagger UI (v3.19.0) - TypeError: Failed to fetch on Chrome
I can see from my server logs that my backend is returning correct 401 responses. I am using gunicorn gateway with keep-alive set...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found