Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

feat(engine): add EngineNotSupportedError (HTTP 501) for gated engine methods

rmyndharis39a2b82f3f8c
diff --git a/src/common/errors/engine-not-supported.error.spec.ts b/src/common/errors/engine-not-supported.error.spec.ts
new file mode 100644
index 000000000..e75031f97
--- /dev/null
+++ b/src/common/errors/engine-not-supported.error.spec.ts
@@ -0,0 +1,11 @@
+import { EngineNotSupportedError } from './engine-not-supported.error';
+
+describe('EngineNotSupportedError', () => {
+ it('carries HTTP 501 so NestJS returns Not Implemented without a custom filter', () => {
+ expect(new EngineNotSupportedError('getGroups').getStatus()).toBe(501);
+ });
+
+ it('names the unsupported operation in the message', () => {
+ expect(new EngineNotSupportedError('getGroups').message).toContain('getGroups');
+ });
+});
diff --git a/src/common/errors/engine-not-supported.error.ts b/src/common/errors/engine-not-supported.error.ts
new file mode 100644
index 000000000..e2a904689
--- /dev/null
+++ b/src/common/errors/engine-not-supported.error.ts
@@ -0,0 +1,16 @@
+import { NotImplementedException } from '@nestjs/common';
+
+/**
+ * Thrown by an engine adapter when a method is part of the {@link IWhatsAppEngine}
+ * contract but the active engine cannot implement it (e.g. the Baileys engine has no
+ * self-maintained store, so history/contacts/groups are unavailable in its minimal slice).
+ *
+ * Extends NestJS `NotImplementedException` so it maps to **HTTP 501** through NestJS's
+ * built-in exception handler — no custom global filter required. Mirrors how
+ * {@link EngineNotReadyError} maps to 409.
+ */
+export class EngineNotSupportedError extends NotImplementedException {
+ constructor(method: string) {
+ super(`Operation not supported by the active engine: ${method}`);
+ }
+}