Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
.catch(error => {
// HACK: Transform query root-level "resource already exists" error to
// mutation specific validation errors. This temporarily simulates how we
// intend to report this error state in the future and can be removed once
// the API has been updated.
if (isApolloError(error) && error.message === RESOURCE_EXISTS_ERROR) {
return {
data: {
createSilence: {
silence: null,
errors: [
{
code: "VALIDATION_UNIQUE_CONSTRAINT",
input: "check",
},
{
code: "VALIDATION_UNIQUE_CONSTRAINT",
input: "subscription",
},
],
},
},
const unwrapError = error => {
if (error instanceof Error) {
const meta = {};
if (error instanceof ReactError) {
return {
componentStack: error.componentStack,
...unwrapError(error.original),
};
}
if (isApolloError(error) && error.networkError) {
return unwrapError(error.networkError);
}
if (error instanceof FetchError) {
if (error.original) {
return {
url: error.url,
statusCode: error.statusCode,
...unwrapError(error.original),
};
}
meta.url = error.url;
meta.statusCode = error.statusCode;
}
const unwrapError = error => {
if (error instanceof Error) {
const meta = {};
if (error instanceof ReactError) {
return {
componentStack: error.componentStack,
...unwrapError(error.original),
};
}
if (isApolloError(error) && error.networkError) {
return unwrapError(error.networkError);
}
if (error instanceof FetchError) {
if (error.original) {
return {
url: error.url,
statusCode: error.statusCode,
...unwrapError(error.original),
};
}
meta.url = error.url;
meta.statusCode = error.statusCode;
}