Skip to content

Commit

Permalink
fix: export QueryErrorClass
Browse files Browse the repository at this point in the history
  • Loading branch information
jackmellis committed Jul 22, 2024
1 parent 19b7fe2 commit 77731fc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/query/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { default as gql } from './gql';
export { default as queryGraph } from './queryGraph';
export { default as createGraphQuery, type QueryBase } from './createQuery';
export { default as query } from './query';
export { default as query, QueryError } from './query';
18 changes: 14 additions & 4 deletions packages/query/src/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@ const globalFetch = typeof fetch === 'undefined' ? undefined : fetch;
type Stringify = typeof JSON.stringify;
type Parse = typeof JSON.parse;

class QueryError extends Error {
constructor(public response: Response, public data: any, message: string) {
export class QueryError extends Error {
constructor(
public response: Response,
public status: number,
public data: any,
message: string
) {
super(message);
}
}
Expand Down Expand Up @@ -114,10 +119,15 @@ const query = async <T>(args: Args): Promise<T> => {
if (!response.ok) {
if (contentType?.includes('application/json')) {
const json = await response.json();
throw new QueryError(response, json, `Error fetching ${url}`);
throw new QueryError(
response,
response.status,
json,
`Error fetching ${url}`
);
} else {
const text = await response.text();
throw new QueryError(response, {}, text);
throw new QueryError(response, response.status, {}, text);
}
}

Expand Down

0 comments on commit 77731fc

Please sign in to comment.