File tree Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -46,6 +46,11 @@ export default async function http(url, request = {}) {
4646 }
4747 }
4848 catch ( resError ) {
49+ if ( ! res ) {
50+ // res is completely absent, so we can't construct our own error
51+ // so we'll just throw the error we got
52+ throw resError
53+ }
4954 const error = new Error ( res . statusText )
5055 error . statusCode = error . status = res . status
5156 error . responseError = resError
Original file line number Diff line number Diff line change @@ -171,6 +171,20 @@ describe('http', () => {
171171 } )
172172 } )
173173
174+ /**
175+ * See https://github.com/swagger-api/swagger-js/issues/1277
176+ */
177+ it ( 'should return a helpful error when the connection is refused' , ( ) => {
178+ return Swagger ( 'http://localhost:1/untouchable.yaml' )
179+ . then ( ( client ) => {
180+ throw new Error ( 'Expected an error.' )
181+ } )
182+ . catch ( ( error ) => {
183+ expect ( error . message ) . toEqual ( 'request to http://localhost:1/untouchable.yaml failed, reason: connect ECONNREFUSED 127.0.0.1:1' )
184+ expect ( error . name ) . toEqual ( 'FetchError' )
185+ } )
186+ } )
187+
174188 /**
175189 * See https://github.com/swagger-api/swagger-js/issues/1002
176190 */
You can’t perform that action at this time.
0 commit comments