improve error handling if notes path fails

This commit is contained in:
korelstar 2020-02-01 22:06:18 +01:00
parent 10d0d6fda5
commit 905d58af63
4 changed files with 25 additions and 16 deletions

View File

@ -64,7 +64,6 @@ class NotesController extends Controller {
* @NoAdminRequired
*/
public function index() {
$notes = $this->notesService->getAll($this->userId, true);
$settings = $this->settingsService->getAll($this->userId);
$errorMessage = null;
@ -74,8 +73,9 @@ class NotesController extends Controller {
'notesLastViewedNote'
);
// check if notes folder is accessible
$notes = null;
try {
$this->notesService->checkNotesFolder($this->userId);
$notes = $this->notesService->getAll($this->userId, true);
if ($lastViewedNote) {
// check if note exists
try {

View File

@ -247,15 +247,6 @@ class NotesService {
return $file[0];
}
/**
* @param string $userId the user id
* @return boolean true if folder is accessible, or Exception otherwise
*/
public function checkNotesFolder($userId) {
$this->getFolderForUser($userId);
return true;
}
/**
* @param string $userId the user id
* @return Folder

View File

@ -17,10 +17,17 @@
@note-deleted="routeFirst"
/>
<AppSettings v-if="!loading.notes && !error" @reload="reloadNotes" />
<AppSettings v-if="!loading.notes && error !== true" @reload="reloadNotes" />
</AppNavigation>
<router-view />
<AppContent v-if="error">
<div style="margin: 2em;">
<h2>{{ t('notes', 'Error') }}</h2>
<p>{{ error }}</p>
<p>{{ t('notes', 'Please chose a valid path in {label} (bottom left corner).', { label: t('notes', 'Settings') }) }}</p>
</div>
</AppContent>
<router-view v-else />
<router-view name="sidebar" />
</Content>
@ -28,6 +35,7 @@
<script>
import {
AppContent,
AppNavigation,
AppNavigationNew,
Content,
@ -42,6 +50,7 @@ export default {
name: 'App',
components: {
AppContent,
AppNavigation,
AppNavigationNew,
AppSettings,
@ -121,7 +130,12 @@ export default {
this.loading.notes = true
NotesService.fetchNotes()
.then(data => {
this.routeDefault(data.lastViewedNote)
if (data.notes !== null) {
this.error = false
this.routeDefault(data.lastViewedNote)
} else {
this.error = data.errorMessage
}
})
.catch(() => {
this.error = true
@ -132,7 +146,9 @@ export default {
},
reloadNotes() {
this.$router.push('/')
if (this.$route.path !== '/') {
this.$router.push('/')
}
store.commit('removeAll')
this.loadNotes()
},

View File

@ -39,7 +39,9 @@ export default {
.get(this.url('/notes'))
.then(response => {
store.commit('setSettings', response.data.settings)
store.dispatch('addAll', response.data.notes)
if (response.data.notes !== null) {
store.dispatch('addAll', response.data.notes)
}
if (response.data.errorMessage) {
OC.Notification.showTemporary(response.data.errorMessage)
}