Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/GraphQL/Client/Query.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const formatError = (err) => {
if (!err) return "";
const props = ["message", "code", "syscall", "hostname", "address", "port"]
.filter((k) => err[k])
.map((k) => `${k}: ${err[k]}`);
if (err.cause) props.push(`cause: ${formatError(err.cause)}`);
return props.join(", ");
};

export const cause = (err) => {
const c = err.cause;
if (!c) return "";
if (c instanceof AggregateError) {
return [
c.message,
...Array.from(c.errors, (e, i) => `[${i}] ${formatError(e)}`),
].join("\n");
}
return formatError(c);
};
4 changes: 4 additions & 0 deletions src/GraphQL/Client/Query.purs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ import GraphQL.Client.Types (class GqlQuery, class QueryClient, Client(..), GqlR
import GraphQL.Client.Variables (class VarsTypeChecked, getVarsJson, getVarsTypeNames)
import Type.Proxy (Proxy(..))

foreign import cause :: Error -> String

-- | Run a graphQL query with a custom decoder and custom options
queryOptsWithDecoder
:: forall client directives schema query returns queryOpts mutationOpts sr
Expand Down Expand Up @@ -261,6 +263,8 @@ addErrorInfo schema queryName q =
<> show queryName
<> ".\nerror: "
<> message err
<> ".\ncause: "
<> cause err
<> ".\nquery: "
<> queryName
<> " "
Expand Down
Loading