|
2 | 2 | <div class="flex flex-col gap-3 w-full">
|
3 | 3 | <div class="flex justify-end">
|
4 | 4 | <Button
|
| 5 | + outlined |
5 | 6 | label=""
|
6 | 7 | size="small"
|
7 |
| - :icon="icon" |
8 | 8 | severity="secondary"
|
9 |
| - outlined |
| 9 | + :disabled="!data" |
| 10 | + :icon="icon" |
10 | 11 | @click="copy"
|
11 | 12 | />
|
12 | 13 | </div>
|
13 | 14 |
|
14 | 15 | <div>
|
15 |
| - <ul v-if="data" v-show="data" class="block rounded border surface-border"> |
| 16 | + <Message |
| 17 | + v-if="errormsg" |
| 18 | + severity="error" |
| 19 | + > |
| 20 | + <div class="flex flex-row items-center"> |
| 21 | + <span>{{ errormsg }}</span> |
| 22 | + <Button |
| 23 | + link |
| 24 | + @click="retryBuildPage" |
| 25 | + class="text-sm" |
| 26 | + > |
| 27 | + Retry |
| 28 | + </Button> |
| 29 | + </div> |
| 30 | + </Message> |
| 31 | + <ul |
| 32 | + v-else-if="data" |
| 33 | + v-show="data" |
| 34 | + class="block rounded border surface-border" |
| 35 | + > |
16 | 36 | <li class="flex flex-row gap-2 border-b surface-border p-2">
|
17 | 37 | <p>
|
18 | 38 | <strong class="text-nowrap">UUID:</strong> {{ data.uuid }}
|
|
74 | 94 | import { onMounted, ref } from 'vue'
|
75 | 95 | import Button from 'primevue/button'
|
76 | 96 | import Skeleton from 'primevue/skeleton'
|
| 97 | + import Message from 'primevue/message' |
77 | 98 |
|
78 | 99 | const service = 'https://netinfo.azion.com/json'
|
79 | 100 | const data = ref(null)
|
80 |
| - const error = ref(null) |
| 101 | + const errormsg = ref(null) |
81 | 102 | const icon = ref('pi pi-copy')
|
82 | 103 |
|
83 | 104 | onMounted(() => {
|
| 105 | + buildpage() |
| 106 | + }) |
| 107 | +
|
| 108 | + const buildpage = () => { |
84 | 109 | getData(service)
|
85 | 110 | .then(json => {
|
86 |
| - if(json.msg) { |
87 |
| - error.value = json.msg |
| 111 | + if(json.message) { |
| 112 | + setMessageError(json.message === 'Failed to fetch' ? 'Network error.' : json) |
88 | 113 | return
|
89 | 114 | }
|
90 | 115 |
|
91 |
| - console.log(json) |
92 | 116 | data.value = parseData(json)
|
93 |
| - console.log(data.value) |
| 117 | + }).catch(error => { |
| 118 | + setMessageError(error.message === 'Failed to fetch' ? 'Network error.' : error) |
94 | 119 | })
|
95 |
| - }) |
| 120 | + } |
| 121 | +
|
| 122 | + const retryBuildPage = () => { |
| 123 | + removeMessageError() |
| 124 | + buildpage() |
| 125 | + } |
| 126 | +
|
| 127 | + const setMessageError = (msg) => { |
| 128 | + errormsg.value = msg |
| 129 | + } |
| 130 | +
|
| 131 | + const removeMessageError = () => { |
| 132 | + errormsg.value = null |
| 133 | + } |
96 | 134 |
|
97 | 135 | const copy = () => {
|
98 | 136 | navigator.clipboard.writeText(JSON.stringify(data.value))
|
|
109 | 147 | if (!response.ok) {
|
110 | 148 | const errorData = {
|
111 | 149 | status: response.status,
|
112 |
| - msg: '[!] Fetch ERRROR to API communication' |
| 150 | + message: '[!] Fetch ERRROR to API communication.' |
113 | 151 | }
|
114 | 152 |
|
115 | 153 | console.error(errorData)
|
116 | 154 | throw new Error(errorData)
|
117 | 155 | }
|
118 | 156 |
|
| 157 | + return response |
| 158 | + }) |
| 159 | + .then(response => { |
119 | 160 | return response.json()
|
120 | 161 | })
|
121 | 162 | .then(json => {
|
122 | 163 | return json
|
123 | 164 | })
|
124 | 165 | .catch(error => {
|
125 |
| - const errorData = { msg: error.message || error } |
126 |
| - console.error(errorData) |
127 |
| - return { msg: errorData } |
| 166 | + console.error(error) |
| 167 | + return error |
128 | 168 | })
|
129 | 169 | }
|
130 | 170 |
|
|
0 commit comments