fix: show server validation errors on 400

This commit is contained in:
abhijithvijayan
2020-03-07 15:00:16 +05:30
parent 3336d5187c
commit 1d60fc671e
2 changed files with 11 additions and 4 deletions

View File

@@ -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: {

View File

@@ -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