From 84e630449cdee56e5df61f408caa268762c7913a Mon Sep 17 00:00:00 2001 From: "Ronald A. Richardson" Date: Thu, 25 Jan 2024 18:24:16 +0800 Subject: [PATCH] patch for fetch uploadFile task and notification to properly get error --- addon/services/fetch.js | 14 +++++++++----- addon/services/notifications.js | 6 +++++- addon/utils/get-resource-name-from-transition.js | 8 +++++++- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/addon/services/fetch.js b/addon/services/fetch.js index e9798db..1cd67b1 100644 --- a/addon/services/fetch.js +++ b/addon/services/fetch.js @@ -548,14 +548,18 @@ export default class FetchService extends Service { this.notifications.serverError(error, 'File upload failed.'); }); - const model = this.store.push(this.store.normalize('file', upload.file)); - set(file, 'model', model); + if (upload) { + const model = this.store.push(this.store.normalize('file', upload.file)); + set(file, 'model', model); - if (typeof callback === 'function') { - callback(model); + if (typeof callback === 'function') { + callback(model); + } + + return model; } - return model; + return null; } catch (error) { queue.remove(file); this.notifications.serverError(error, 'File upload failed.'); diff --git a/addon/services/notifications.js b/addon/services/notifications.js index c0f93a4..3cd8e99 100644 --- a/addon/services/notifications.js +++ b/addon/services/notifications.js @@ -16,7 +16,11 @@ export default class NotificationsService extends EmberNotificationsService { return this.error(errorMessage, options); } - return this.error(error ?? fallbackMessage, options); + if (typeof error === 'string') { + return this.error(error, options); + } + + return this.error(fallbackMessage, options); } invoke(type, message, ...params) { diff --git a/addon/utils/get-resource-name-from-transition.js b/addon/utils/get-resource-name-from-transition.js index a8a7037..ff745ae 100644 --- a/addon/utils/get-resource-name-from-transition.js +++ b/addon/utils/get-resource-name-from-transition.js @@ -1,10 +1,16 @@ -export default function getResourceNameFromTransition(transition) { +import humanize from './humanize'; + +export default function getResourceNameFromTransition(transition, options = {}) { const { to } = transition; if (typeof to.name === 'string') { let routePathSegments = to.name.split('.'); let resourceName = routePathSegments[3]; + if (options.humanize === true) { + return humanize(resouceName); + } + return resourceName; }