add types for axios errors.

This commit is contained in:
Miroslav Šedivý
2023-09-24 23:11:18 +02:00
parent 224e84f9b5
commit 122903a2b0
5 changed files with 37 additions and 15 deletions
+13 -5
View File
@@ -53,6 +53,7 @@
<script lang="ts">
import { Vue, Component } from 'vue-property-decorator'
import { AxiosError } from 'axios'
@Component
export default class Pull extends Vue {
@@ -74,10 +75,11 @@ export default class Pull extends Vue {
try {
await this.$store.dispatch('PULL_START', this.nekoImage)
} catch(e) {
if (e.response) {
const response = (e as AxiosError).response
if (response) {
this.$swal({
title: 'Server error',
text: e.response.data,
text: response.data,
icon: 'error',
})
} else {
@@ -98,10 +100,11 @@ export default class Pull extends Vue {
try {
await this.$store.dispatch('PULL_STOP')
} catch(e) {
if (e.response) {
const response = (e as AxiosError).response
if (response) {
this.$swal({
title: 'Server error',
text: e.response.data,
text: response.data,
icon: 'error',
})
} else {
@@ -128,7 +131,12 @@ export default class Pull extends Vue {
try {
await this.$store.dispatch('PULL_STATUS')
} catch(e) {
console.error(e)
const response = (e as AxiosError).response
if (response) {
console.error('Server error', response.data)
} else {
console.error('Network error', String(e))
}
}
}, 1000)
}
+4 -2
View File
@@ -9,6 +9,7 @@
<script lang="ts">
import { Vue, Component, Prop } from 'vue-property-decorator'
import { AxiosError } from 'axios'
@Component
export default class RoomActionBtn extends Vue {
@@ -102,10 +103,11 @@ export default class RoomActionBtn extends Vue {
icon: 'success',
})
} catch(e) {
if (e.response) {
const response = (e as AxiosError).response
if (response) {
this.$swal({
title: 'Server error',
text: e.response.data,
text: response.data,
icon: 'error',
})
} else {
+10 -3
View File
@@ -206,6 +206,7 @@
<script lang="ts">
import { Vue, Component, Prop, Watch } from 'vue-property-decorator'
import { AxiosError } from 'axios'
import RoomLink from './RoomLink.vue'
import {
@@ -247,10 +248,11 @@ export default class RoomInfo extends Vue {
this.LoadStats()
}
} catch(e) {
if (e.response) {
const response = (e as AxiosError).response
if (response) {
this.$swal({
title: 'Server error',
text: e.response.data,
text: response.data,
icon: 'error',
})
} else {
@@ -288,7 +290,12 @@ export default class RoomInfo extends Vue {
this.stats = stats
this.statsErr = ""
} catch(e) {
this.statsErr = e
const response = (e as AxiosError).response
if (response) {
this.statsErr = `Server error: ${response.data}`
} else {
this.statsErr = `Network error: ${String(e)}`
}
} finally {
this.statsLoading = false
}
+4 -2
View File
@@ -492,6 +492,7 @@
<script lang="ts">
import { Vue, Component, Ref, Watch } from 'vue-property-decorator'
import { AxiosError } from 'axios'
import { randomPassword } from '@/utils/random'
import {
@@ -700,10 +701,11 @@ export default class RoomsCreate extends Vue {
this.Clear()
this.$emit('finished', true)
} catch(e) {
if (e.response) {
const response = (e as AxiosError).response
if (response) {
this.$swal({
title: 'Server error',
text: e.response.data,
text: response.data,
icon: 'error',
})
} else {
+6 -3
View File
@@ -46,9 +46,11 @@
<script lang="ts">
import { Vue, Component } from 'vue-property-decorator'
import RoomInfo from '@/components/RoomInfo.vue'
import { AxiosError } from 'axios'
import { randomPassword } from '@/utils/random'
import RoomInfo from '@/components/RoomInfo.vue'
@Component({
components: {
RoomInfo,
@@ -81,10 +83,11 @@ export default class RoomActionBtn extends Vue {
this.roomId = entry.id
this.dialog = true
} catch(e) {
if (e.response) {
const response = (e as AxiosError).response
if (response) {
this.$swal({
title: 'Server error',
text: e.response.data,
text: response.data,
icon: 'error',
})
} else {