Skip to content

Commit

Permalink
fix: fix errors handle (monicahq/chandler#487)
Browse files Browse the repository at this point in the history
  • Loading branch information
asbiin authored May 6, 2023
1 parent 721abb9 commit 8e2d5f8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 17 deletions.
8 changes: 7 additions & 1 deletion resources/js/Pages/Vault/Files/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@

<!-- right -->
<div class="p-3 sm:px-3 sm:py-0">
<errors :errors="errors" />

<!-- title + cta -->
<div class="mb-6 flex items-center justify-between">
<h3>
Expand Down Expand Up @@ -121,12 +123,14 @@
import Layout from '@/Shared/Layout.vue';
import Avatar from '@/Shared/Avatar.vue';
import Pagination from '@/Components/Pagination.vue';
import Errors from '@/Shared/Form/Errors.vue';
export default {
components: {
Layout,
Avatar,
Pagination,
Errors,
},
props: {
Expand All @@ -151,6 +155,7 @@ export default {
data() {
return {
localFiles: [],
errors: [],
};
},
Expand All @@ -161,6 +166,7 @@ export default {
methods: {
destroy(file) {
if (confirm(this.$t('Are you sure? This action cannot be undone.'))) {
this.errors = [];
axios
.delete(file.url.destroy)
.then(() => {
Expand All @@ -169,7 +175,7 @@ export default {
this.localFiles.splice(id, 1);
})
.catch((error) => {
this.form.errors = error.response.data;
this.errors = error.response.data;
});
}
},
Expand Down
39 changes: 23 additions & 16 deletions resources/js/Shared/Form/Errors.vue
Original file line number Diff line number Diff line change
@@ -1,20 +1,8 @@
<template>
<div>
<div v-if="dataerror || exception" class="border-red mb-3 rounded border p-3" v-bind="$attrs">
<p class="mb-2 text-sm">{{ $t('Oops! Something went wrong.') }}</p>
<template v-if="dataerror">
<p v-if="flatten[0] != 'The given data was invalid.'" class="mb0">
{{ flatten[0] }}
</p>
<template v-if="display(flatten[1])">
<p v-for="errorsList in flatten[1]" :key="errorsList.id">
<span v-for="error in errorsList" :key="error.id" class="mb0 mt2">
{{ error }}
</span>
</p>
</template>
</template>
<template v-else-if="exception">
<p class="mb-2">{{ $t('Oops! Something went wrong.') }}</p>
<template v-if="exception">
<p class="mb0">
{{ errors.message }}
</p>
Expand All @@ -29,11 +17,30 @@
{{ errors.exception }}
</span>
<br />
<span v-for="trace in errors.trace" :key="trace.id">
{{ trace.class }}{{ trace.type }}{{ trace.function }}<br />
<span v-for="trace in errors.trace" :key="trace.id" class="text-xs">
{{
$t(':file in :class at line :line', {
file: trace.file,
class: `${trace.class}${trace.type}${trace.function}`,
line: trace.line,
})
}}
<br />
</span>
</p>
</template>
<template v-else-if="dataerror">
<!-- <p v-if="flatten[0] !== $t('The given data was invalid.')" class="mb0">
{{ flatten[0] }}
</p> -->
<template v-if="display(flatten[1])">
<p v-for="errorsList in flatten[1]" :key="errorsList.id">
<span v-for="error in errorsList" :key="error.id" class="mb0 mt2 text-sm">
{{ error }}
</span>
</p>
</template>
</template>
</div>
</div>
</template>
Expand Down

0 comments on commit 8e2d5f8

Please sign in to comment.