UNPKG

843 BJavaScriptView Raw
1function _buildMessageForResponseErrors(data) {
2 return (`Request failed due to following response errors:\n` +
3 data.errors.map((e) => ` - ${e.message}`).join("\n"));
4}
5export class GraphqlResponseError extends Error {
6 constructor(request, headers, response) {
7 super(_buildMessageForResponseErrors(response));
8 this.request = request;
9 this.headers = headers;
10 this.response = response;
11 this.name = "GraphqlResponseError";
12 // Expose the errors and response data in their shorthand properties.
13 this.errors = response.errors;
14 this.data = response.data;
15 // Maintains proper stack trace (only available on V8)
16 /* istanbul ignore next */
17 if (Error.captureStackTrace) {
18 Error.captureStackTrace(this, this.constructor);
19 }
20 }
21}