Skip to content

Commit

Permalink
patch for fetch uploadFile task and notification to properly get error
Browse files Browse the repository at this point in the history
  • Loading branch information
roncodes committed Jan 25, 2024
1 parent a318354 commit 84e6304
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
14 changes: 9 additions & 5 deletions addon/services/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
Expand Down
6 changes: 5 additions & 1 deletion addon/services/notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
8 changes: 7 additions & 1 deletion addon/utils/get-resource-name-from-transition.js
Original file line number Diff line number Diff line change
@@ -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;
}

Expand Down

0 comments on commit 84e6304

Please sign in to comment.