chore: make changes in codebase after error contract change

This commit is contained in:
Jacob Nguyen
2023-05-19 20:30:32 -05:00
parent d7195c45b3
commit fc6206a205
4 changed files with 12 additions and 5 deletions

View File

@@ -8,7 +8,8 @@ export interface ErrorHandling {
keepAlive: number;
/**
* A function that is called on every crash. Updates keepAlive
* A function that is called on every crash. Updates keepAlive.
* If keepAlive is 0, the process crashes.
* @param error
*/
updateAlive(error: Error): void;

View File

@@ -23,9 +23,7 @@ export function makeEventsHandler(
case EventType.External:
return eventDispatcher(e, Service(e.emitter));
default:
return err.crash(
Error(SernError.InvalidModuleType + ' while creating event handler'),
);
throw Error(SernError.InvalidModuleType + ' while creating event handler');
}
};
of(null)

View File

@@ -15,6 +15,7 @@ export function reconstructId<T extends Interaction>(event: T) {
case InteractionType.ApplicationCommandAutocomplete: {
return `${event.commandName}_A${event.commandType}`;
}
//Modal interactions are classified as components for sern
case InteractionType.ModalSubmit: {
return `${event.customId}_C1`;
}

View File

@@ -56,7 +56,14 @@ describe('services', () => {
//todo add more
it('error-handling', () => {
const errorHandler = container.get('@sern/errors');
expect(() => errorHandler.crash(new Error("poo"))).toThrowError();
const lifetime = errorHandler.keepAlive;
for(let i = 0; i< lifetime; i++) {
if(i == lifetime-1) {
expect(() => errorHandler.updateAlive(new Error("poo"))).toThrowError();
} else {
expect(() => errorHandler.updateAlive(new Error("poo"))).not.toThrowError();
}
}
})
//todo add more, spy on every instance?