Skip to content

Commit

Permalink
catch error in promise
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinMachado committed Aug 22, 2023
1 parent dd75156 commit 5c283c6
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,12 @@ export class DocumentProvider extends EventSender {
*/
async refreshDocumentList() {
const previousDocument = this.getDisplayedDocument();
this.allDocuments = await this.service.fetchDocuments();
this.allDocuments = await this.service
.fetchDocuments()
.catch((error) => console.log(error));

if (!this.allDocuments) return;

this.filteredDocuments = this.allDocuments.slice();

for (const filter of this.filters) {
Expand All @@ -85,11 +90,11 @@ export class DocumentProvider extends EventSender {
} else {
this.displayedDocumentIndex = undefined;
}
await this.sendEvent(
this.sendEvent(
DocumentProvider.EVENT_FILTERED_DOCS_UPDATED,
this.getFilteredDocuments()
);
await this.sendEvent(
this.sendEvent(
DocumentProvider.EVENT_DISPLAYED_DOC_CHANGED,
this.getDisplayedDocument()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,12 @@ export class GuidedTour extends EventSender {
* Get all available guided tour from the database
*/
startGuidedTourMode() {
this.guidedTourController.getGuidedTours().then(() => {
this.previewTour();
});
this.guidedTourController
.getGuidedTours()
.then(() => {
this.previewTour();
})
.catch((error) => console.log(error));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,19 @@ export class GuidedTourController {
/**
* Get all guided tour from a database
*/
async getGuidedTours() {
const req = await this.requestService.request('GET', this.url, {
authenticate: false,
getGuidedTours() {
return new Promise((resolve, reject) => {
const req = this.requestService
.request('GET', this.url, {
authenticate: false,
})
.then(() => {
this.guidedTours = JSON.parse(req.responseText);
if (!this.guidedTours.length) reject('NO GUIDED TOUR ON SERVER');
resolve();
})
.catch(reject);
});
this.guidedTours = JSON.parse(req.responseText);
if (!this.guidedTours.length) console.warn('NO GUIDED TOUR ON SERVER');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/src/EventSender.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class EventSender {
* @param {string} event The event to fire. Must be first registered.
* @param {*} data The optional data to pass as parameter.
*/
async sendEvent(event, data = null) {
sendEvent(event, data = null) {
const listeners = this.eventListeners[event];
if (listeners) {
for (const action of listeners) {
Expand Down

0 comments on commit 5c283c6

Please sign in to comment.