mirror of
https://github.com/thedevs-network/kutt-extension.git
synced 2026-02-03 13:53:23 +00:00
fix: handle shortening submission using try-catch in background-scripts
This commit is contained in:
@@ -17,19 +17,33 @@ export type ShortenUrlBodyProperties = {
|
||||
domain: string;
|
||||
};
|
||||
|
||||
function shortenUrl(params: ShortenUrlBodyProperties): AxiosPromise<any> {
|
||||
// ToDo: get apikey from local storage
|
||||
return api({
|
||||
method: 'POST',
|
||||
timeout: constants.SHORTEN_URL_TIMEOUT,
|
||||
url: `/api/v2/links`,
|
||||
headers: {
|
||||
'X-API-Key': 'replace-with-api-key',
|
||||
},
|
||||
data: {
|
||||
...params,
|
||||
},
|
||||
});
|
||||
async function shortenUrl(params: ShortenUrlBodyProperties): AxiosPromise<any> {
|
||||
try {
|
||||
// ToDo: get apikey from local storage
|
||||
const { data } = await api({
|
||||
method: 'POST',
|
||||
timeout: constants.SHORTEN_URL_TIMEOUT,
|
||||
url: `/api/v2/links`,
|
||||
headers: {
|
||||
'X-API-Key': 'replace-with-api-key',
|
||||
},
|
||||
data: {
|
||||
...params,
|
||||
},
|
||||
});
|
||||
|
||||
console.log(data);
|
||||
} catch (err) {
|
||||
if (err.response) {
|
||||
if (err.response.status === 401) {
|
||||
// 'Error: Invalid API Key'
|
||||
}
|
||||
}
|
||||
|
||||
if (err.code === 'ECONNABORTED') {
|
||||
// timed-out
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getUserSettings(apikey: string): AxiosPromise<any> {
|
||||
|
||||
@@ -105,11 +105,8 @@ const PopupForm = withFormik<PopupFormProperties, FormValuesProperties>({
|
||||
domain, // ToDo: validate this
|
||||
};
|
||||
|
||||
try {
|
||||
await messageUtil.send(SHORTEN_URL, data);
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
}
|
||||
const response = await messageUtil.send(SHORTEN_URL, data);
|
||||
console.log(response);
|
||||
|
||||
setSubmitting(false);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user