Add error message for missing subnet

This commit is contained in:
Maarten 2024-11-26 08:46:10 +01:00
parent 9aae3144fe
commit ff404be6c0

View file

@ -15,7 +15,14 @@ const results = ref( {} );
/** /**
* Load subnet data based on input * Load subnet data based on input
*/ */
const getSubnetData = async () => { const getSubnetData = async (): void => {
// Check if subnet is filled
if (subnet.value === '') {
errorMsg('Subnet is required');
return;
}
try { try {
// Enable loading state // Enable loading state
isLoading.value = true; isLoading.value = true;
@ -34,10 +41,7 @@ const getSubnetData = async () => {
} catch (error) { } catch (error) {
// Extract and show error message // Extract and show error message
const errorMessage = error.response?.data?.message || 'Something went wrong.'; const errorMessage = error.response?.data?.message || 'Something went wrong.';
$toast.error(errorMessage, { errorMsg(errorMessage);
position: 'top',
duration: 1500,
});
} finally { } finally {
// Reset loading state // Reset loading state
isLoading.value = false; isLoading.value = false;
@ -47,12 +51,24 @@ const getSubnetData = async () => {
/** /**
* Reset form by resetting al vars * Reset form by resetting al vars
*/ */
const resetForm = () => { const resetForm = (): void => {
subnet.value = ''; subnet.value = '';
isLoading.value = false; isLoading.value = false;
hasResults.value = false; hasResults.value = false;
results.value = {}; results.value = {};
} }
/**
* Send error message
*
* @param message
*/
const errorMsg = (message: string): void => {
$toast.error(message, {
position: 'top',
duration: 1500,
});
}
</script> </script>
<template> <template>