Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const execute = async (): Promise => {
try {
const response: any = await ky
.post(this.url, {
json: {
query: this.createQuery(query),
variables
},
signal: options.signal,
hooks: this.options.hooks,
timeout: options.timeout || this.options.timeout
})
.json();
// GraphQL servers don't fail the request, even if resolvers are failing
// They still return 200 status code, but add `errors` field in the response
if (Array.isArray(response.errors)) {
const errors = response.errors.map((error: any) => {
const error2 = new Error(error.message) as any;
const submit = React.useCallback(async () => {
if (badUrl) return;
setResult(null);
setError(null);
let result: APIResponse;
try {
result = await ky
.post('shorten', {
prefixUrl: location.origin,
json: { url, code }
})
.json();
} catch (err) {
const b = await err.response.json();
console.log(b);
console.error(err);
setError(err);
return;
}
setResult(result.url);
}, [badUrl, code, url]);
const submit = React.useCallback(async () => {
if (!key) return;
setError(null);
try {
await ky.post('auth', {
prefixUrl: location.origin,
json: { key }
});
router.push('/add');
} catch (err) {
console.error(err);
setError(err);
}
}, [key, router]);
public async post(url: string, data?: any): Promise {
return ky.post(url, { prefixUrl, json: data }).json();
}