I am trying to upgrade my application from V2 to V3, however whenever I throw a Meteor.Error()
from another file, the entire application crashes, rather than just returning the error to the client.
Client calls getAnnouncement
method:
getAnnouncement: async function({ announcementID }) {
this.unblock();
check(announcementID, String);
Security.checkLoggedIn(this.userId);
Security.hasRole(this.userId, [
"supplier_community_read"
//"retailer_community_read"
]);
return await AnnouncementService.getAnnouncement(
announcementID,
this.userId
);
},
The Security class methods, checkLoggedIn
and hasRole
should run to validate the user permissions:
static async hasRole(userId, role) {
if (Meteor.isTest) return true;
const auth = await Roles.userIsInRoleAsync(userId, role);
if (!auth) {
throw new Meteor.Error(403, "[Security.hasRole] Not Authorized");
}
return auth;
}
Rather than the method returning the thrown error from the Security.hasRole
method, the application is just crashing:
W20250322-12:27:18.722(-5)? (STDERR) errorClass [Error]: [Security.hasRole] Not Authorized [403]
W20250322-12:27:18.722(-5)? (STDERR) at Function.hasRole (imports/api/services/Security/index.js:17:10)
W20250322-12:27:18.723(-5)? (STDERR) at processTicksAndRejections (node:internal/process/task_queues:105:5) {
W20250322-12:27:18.723(-5)? (STDERR) isClientSafe: true,
W20250322-12:27:18.723(-5)? (STDERR) error: 403,
W20250322-12:27:18.723(-5)? (STDERR) reason: '[Security.hasRole] Not Authorized',
W20250322-12:27:18.723(-5)? (STDERR) details: undefined,
W20250322-12:27:18.723(-5)? (STDERR) errorType: 'Meteor.Error'
W20250322-12:27:18.723(-5)? (STDERR) }
W20250322-12:27:18.723(-5)? (STDERR)
W20250322-12:27:18.723(-5)? (STDERR) Node.js v22.13.1
=> Exited with code: 7
=> Your application is crashing. Waiting for file change.
In V2, when calling the Security methods if the user did not have the correct permissions, the error would be thrown to the client. App would not crash.
In V3, when calling the Security methods if the user does not have the correct permissions, the error is being thrown to the terminal and the App is crashing.
Has anyone experienced a similar issue?