mirror of
https://github.com/thedevs-network/kutt-extension.git
synced 2026-02-03 13:53:23 +00:00
fix: show server validation errors on 400
This commit is contained in:
@@ -74,6 +74,14 @@ async function shortenUrl(
|
||||
message: 'Error: Invalid API Key',
|
||||
};
|
||||
}
|
||||
|
||||
// server request validation errors
|
||||
if (err.response.status === 400 && Object.prototype.hasOwnProperty.call(err.response.data, 'error')) {
|
||||
return {
|
||||
error: true,
|
||||
message: `Error: ${err.response.data.error}`,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
if (err.code === 'ECONNABORTED') {
|
||||
@@ -162,8 +170,6 @@ async function checkApiKey(apikey: string): Promise<SuccessfulApiKeyCheckPropert
|
||||
* Listen for messages from UI
|
||||
*/
|
||||
browser.runtime.onMessage.addListener((request, _sender): void | Promise<any> => {
|
||||
console.log('message received', request);
|
||||
|
||||
// eslint-disable-next-line default-case
|
||||
switch (request.action) {
|
||||
case constants.CHECK_API_KEY: {
|
||||
|
||||
@@ -81,7 +81,7 @@ const PopupForm = withFormik<PopupFormProperties, PopupFormValuesProperties>({
|
||||
// ToDo: Remove special symbols from password & customurl fields
|
||||
|
||||
// password validation
|
||||
if (values.password && values.password.trim().length < 3) {
|
||||
if (values.password && values.password.trim().length < 1) {
|
||||
errors.password = 'Password must be atleast 3 characters';
|
||||
}
|
||||
// custom url validation
|
||||
@@ -122,7 +122,8 @@ const PopupForm = withFormik<PopupFormProperties, PopupFormValuesProperties>({
|
||||
...(customurl.trim() !== '' && { customurl: customurl.trim() }), // add this key only if field is not empty
|
||||
...(password.trim() !== '' && { password: password.trim() }),
|
||||
reuse: false,
|
||||
...(domain.trim() !== '' && { domain: domain.trim() }),
|
||||
// ToDo: restore when https://github.com/thedevs-network/kutt/issues/287 is resolved
|
||||
// ...(domain.trim() !== '' && { domain: domain.trim() }),
|
||||
};
|
||||
|
||||
// shorten url in the background
|
||||
|
||||
Reference in New Issue
Block a user