Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: failed to fetch is vague and unpleasant to look at when a request fails #4560

Closed
shockey opened this issue May 16, 2018 · 3 comments · Fixed by #6938
Closed

TypeError: failed to fetch is vague and unpleasant to look at when a request fails #4560

shockey opened this issue May 16, 2018 · 3 comments · Fixed by #6938

Comments

@shockey
Copy link
Contributor

shockey commented May 16, 2018

Content & configuration

Example Swagger/OpenAPI definition:

openapi: 3.0.0
servers: 
- url: http://kyles.hockey:1234/this/wont/work
info:
  title: test
  version: test
paths:
  '/':
    get:
      responses:
        '200':
          description: Successful response

Current behavior

image

TypeError: failed to fetch appears, giving me no clues as to what went wrong - a refused connection, in this case.

To reproduce...

Steps to reproduce the behavior:

  1. Expand the operation in the provided example document
  2. Click Execute to fire an ill-fated request

Desired behavior

A styled UI element that appears instead of the regular live response display UI would more clearly indicate that no response was received at all, and displaying the browser's error reason would give me actionable information without having to open my browser console.

Additional context or thoughts

cc #3403.

@reece
Copy link

reece commented Nov 26, 2018

I hit this error during local development (i.e., had nothing to do with AWS that was reported in #3403). The underlying cause (CORS violation) is identical. It would have been helpful for "TypeError: Failed to fetch" to provide more information or at least suggest a CORS violation.

Details: I set up connexion with an openapi spec that referred to http://localhost:9090/. When the development server starts, it says "Running on http://0.0.0.0:9090/". That page appears to work, but the swagger ui uses http://localhost:9090/ from the openapi spec for subsequent requests and shows TypeError: Failed to fetch in results. The browser console shows Access to fetch at 'http://localhost:9090/vr/variation' from origin 'http://0.0.0.0:9090'. (Connexion is based on Python flask and provides extended support for openapi integration, including swagger ui.)

adamdecaf added a commit to moov-io/fed that referenced this issue Mar 6, 2019
If you run this app locally and use the OpenAPI editor to query
endpoints 'GET /ping' needs to respond with CORS headers. Otherwise
the swagger-editor (incorrectly) succeeds on the request but complains
the request failed.

See: https://editor.swagger.io/

Issue: swagger-api/swagger-ui#4560
@CarlosHAraujo
Copy link

I have faced this issue while trying to access a 302 to Azure Blob Storage.
Console error message says:
Access to fetch at 'https://obfuscated' (redirected from 'https://localhost:5001/obfuscated') from origin 'https://localhost:5001' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

It seems to be an issue with swagger-ui, since I can download the file successfully using POSTMAN.

@mathis-m
Copy link
Contributor

I have faced this issue while trying to access a 302 to Azure Blob Storage.
Console error message says:
Access to fetch at 'https://obfuscated' (redirected from 'https://localhost:5001/obfuscated') from origin 'https://localhost:5001' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

It seems to be an issue with swagger-ui, since I can download the file successfully using POSTMAN.

@CarlosHAraujo Postman doesn't care about SOP, it's a dev tool not a browser. Since swagger-ui runs in browser it is limited to its security features like CORS policy. Just make sure the server sends correct cors headers. If you can't controll the server you probably need a middleware that will set the CORS headers accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants