Swagger Editor shows "Failed to fetch" error

M.Shute picture M.Shute · Apr 12, 2017 · Viewed 24.5k times · Source

I'm new to Swagger and using Swagger Editor running locally on my desktop to test an API. I'm not responsible for server configuration, and have no access to make changes. I have my security definitions set up and my authorization working. Now I'm trying to set up my first path schema, but when I execute it, I get an error message that says "TypeError: Failed to fetch" and the Response Headers field is empty.

enter image description here

However, when I copy the Curl request provided by Swagger Editor and run it in GitBash, it returns the value I expect. So I know that Swagger Editor has created a working request.

I know that my security authorization is working because I can see the token it returns in the Curl request.

The authentication schema and the path schema both hit different sub-domains. Authentication is handled by betaauthorize.myDomain.com while the path is handled by betaapi.myDoamin.com.

The errors I'm getting in the browser console don't mean much to me. enter image description here

Again, I'm running Swagger Editor from my desktop hard drive. Is there some kind of Swagger Editor config setting that I'm missing? Is there a server config issue that I need to make the server admins aware of? I've been trying to figure this out for two days and I'm all out of ideas. Any suggestions would be appreciated.

Answer

M.Shute picture M.Shute · Apr 24, 2017

It turns out that my code was requiring an authorization key for all requests, including OPTIONS requests. After some research and consultation, I determined that it's best practice to respond to OPTIONS requests without any authorization - authorization should be required on the subsequent requests. Once I modified the code to proceed without authorization for OPTIONS requests, I was able to get Swagger working for my project.