Error feedback

This commit is contained in:
Douglas Barone 2023-10-24 07:31:50 -04:00
parent 8b3c77cc92
commit 76ef520f3e
3 changed files with 33 additions and 10 deletions

View File

@ -21,8 +21,8 @@ export async function login(username: string, password: string, ip: string) {
await pa.login(username, ip, user.domain)
return user
} catch (error) {
console.log(error)
throw new Error('Login failed')
} catch (error: any) {
console.log(error.message)
throw new Error(`Login failed: ${error.message}`)
}
}

View File

@ -0,0 +1,25 @@
<template>
<v-alert class="mt-5" type="error" v-if="error" prominent variant="tonal">
<div>
Não foi possível fazer login. Tente novamente. Se o problema persistir,
entre em contato com o SERTI do campus.
<a href="" @click.prevent="showDetails = !showDetails" variant="plain">
Mostrar detalhes
</a>
</div>
<code v-if="showDetails">
{{ error }}
</code>
</v-alert>
</template>
<script lang="ts" setup>
import { ref } from 'vue'
defineProps({
error: String
})
const showDetails = ref(false)
</script>

View File

@ -55,10 +55,7 @@
</v-card-actions>
</v-card>
<v-scale-transition>
<v-alert class="mt-5" type="error" v-if="error">
Não foi possível fazer login. Tente novamente. Se o problema persistir,
entre em contato com o SERTI do campus.
</v-alert>
<login-error-alert :error="error" />
</v-scale-transition>
</v-form>
</template>
@ -67,6 +64,7 @@
import { ref, computed } from 'vue'
import { trpc } from '../trpc'
import { VForm } from 'vuetify/lib/components/index.mjs'
import LoginErrorAlert from './LoginErrorAlert.vue'
const emit = defineEmits(['login'])
@ -78,7 +76,7 @@ const showPassword = ref(false)
const loading = ref(false)
const error = ref(false)
const error = ref('')
const form = ref<VForm>()
@ -89,7 +87,7 @@ const valid = computed(() => {
async function doLogin() {
try {
loading.value = true
error.value = false
error.value = ''
const loginResult = await trpc.login.mutate({
username: username.value,
@ -99,7 +97,7 @@ async function doLogin() {
emit('login', loginResult)
} catch (e: any) {
console.log(e.message)
error.value = true
error.value = e.message
} finally {
loading.value = false
}