From f6cd9b76d38800e1a1f63d07152fc96cda562795 Mon Sep 17 00:00:00 2001
From: Corentin Thomasset <corentin.thomasset74@gmail.com>
Date: Thu, 4 Aug 2022 22:57:24 +0200
Subject: refactor(dry): mutualised duplicated code with withDefaultOnError

---
 src/tools/url-parser/url-parser.vue | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

(limited to 'src/tools/url-parser/url-parser.vue')

diff --git a/src/tools/url-parser/url-parser.vue b/src/tools/url-parser/url-parser.vue
index 1978e14..78b732a 100644
--- a/src/tools/url-parser/url-parser.vue
+++ b/src/tools/url-parser/url-parser.vue
@@ -30,16 +30,12 @@
 import { computed, ref } from 'vue';
 import { SubdirectoryArrowRightRound } from '@vicons/material';
 import { useValidation } from '@/composable/validation';
+import { withDefaultOnError } from '@/utils/defaults';
 import InputCopyable from '../../components/InputCopyable.vue';
 
 const urlToParse = ref('https://me:pwd@it-tools.tech:3000/url-parser?key1=value&key2=value2#the-hash');
-const urlParsed = computed<URL | undefined>(() => {
-  try {
-    return new URL(urlToParse.value);
-  } catch (_) {
-    return undefined;
-  }
-});
+
+const urlParsed = computed(() => withDefaultOnError(() => new URL(urlToParse.value), undefined));
 const validation = useValidation({
   source: urlToParse,
   rules: [
-- 
cgit v1.2.3

