INNER CODE UNIT · TypeScript
buildErrorObject
logaretm/villus · packages/batch/src/index.ts:157
function buildErrorObject(response: ParsedResponse<unknown>, opIdx: number) {
// It is possible than a non-200 response is returned with errors, it should be treated as GraphQL error
const ctorOptions: { response: typeof response; graphqlErrors?: GraphQLError[]; networkError?: Error } = {
response,
};
if (Array.isArray(response.body)) {
const opResponse = response.body[opIdx];
ctorOptions.graphqlErrors = opResponse?.errors;
} else if (response.body?.errors) {
ctorOptions.graphqlErrors = response.body.errors;
} else {
ctorOptions.networkError = new Error(response.statusText);
}
return new CombinedError(ctorOptions);
}