-
Notifications
You must be signed in to change notification settings - Fork 101
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
Rethrow human-readable error on schema introspection #50
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -153,7 +153,23 @@ const executeQueryFromTerminalUI = async (queryOptions, successCb, errorCb) => | |
headers, | ||
} = queryOptions; | ||
cli.action.start('Introspecting schema'); | ||
const schemaResponse = await query({endpoint: endpoint, query: introspectionQuery, headers: headers}); | ||
|
||
const schemaResponse = await query({endpoint: endpoint, query: introspectionQuery, headers: headers}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A better readable way for catching errors in the async await pattern is: let schemaResponse;
try {
schemaResponse = await query({...})
} catch (e) {
// throw
} |
||
.catch(err => { | ||
if (err.message && err.message.startsWith('Network error: Unexpected token')) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @BlackDahila you might want to check this condition. I tried running the command: ./bin/run http://localhost:random --introspect It gave me this error:
|
||
const {networkError} = err; | ||
|
||
throw new Error( | ||
`Invalid GraphQL endpoint${ | ||
networkError ? | ||
`: [${networkError.statusCode}] ${networkError.response.statusText}` : | ||
'' | ||
}`); | ||
} | ||
|
||
throw err; | ||
}); | ||
|
||
cli.action.stop('done'); | ||
const r = schemaResponse.data; | ||
// term.fullscreen(true); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe you want to do this assignment after you check if
queryString
is null.Assigning here and spreading later is just an extra step IMO.