Skip to content

Commit

Permalink
Proper error message for introspection querying
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov committed Mar 23, 2017
1 parent 9c84f9c commit 41837fd
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/proxy.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
global['fetch'] = require('node-fetch');

import {Response} from 'node-fetch';
import * as set from 'lodash/set.js';
import * as FetchQL from 'fetchql';
import {
Expand Down Expand Up @@ -27,9 +28,25 @@ type RequestInfo = {

export function proxyMiddleware(url, headers) {
const remoteServer = new FetchQL({url, headers});
const errorPrefix = `Can't get introspection from ${url}:\n`;

return remoteServer.query({query: introspectionQuery})
.catch(errors => {
if (errors[0].stack instanceof Response) {
const errResponce = errors[0].stack;
return errResponce.text().then(body => { throw Error(
errorPrefix +`${errResponce.status} ${errResponce.statusText}\n${body}`
)});
}
return {errors};
})
.then(introspection => {
if (introspection.errors) {
throw Error(
errorPrefix + JSON.stringify(introspection.errors, null, 2)
);
}

return remoteServer.query({query: introspectionQuery}).then(introspection => {
// TODO: check for errors
const introspectionSchema = buildClientSchema(introspection.data);
const introspectionIDL = printSchema(introspectionSchema);

Expand Down

0 comments on commit 41837fd

Please sign in to comment.