diff --git a/memorylayer-core-python/src/memorylayer_server/services/ontology/base.py b/memorylayer-core-python/src/memorylayer_server/services/ontology/base.py index 88eb388..df7e4c7 100644 --- a/memorylayer-core-python/src/memorylayer_server/services/ontology/base.py +++ b/memorylayer-core-python/src/memorylayer_server/services/ontology/base.py @@ -4,11 +4,11 @@ class FeatureRequiresUpgradeError(Exception): - """Raised when a feature requires enterprise upgrade.""" + """Raised when a feature requires the MemoryLayer Enterprise extensions.""" def __init__(self, feature: str): self.feature = feature - super().__init__(f"Feature '{feature}' requires MemoryLayer Enterprise. Visit https://memorylayer.ai/enterprise to upgrade.") + super().__init__(f"Feature '{feature}' requires MemoryLayer Enterprise (open source, AGPL-3.0): https://github.com/scitrera/memorylayer-enterprise") # Unified ontology. The compact knowledge-work application profile below is diff --git a/memorylayer-sdk-go/client.go b/memorylayer-sdk-go/client.go index d3fb378..00f1845 100644 --- a/memorylayer-sdk-go/client.go +++ b/memorylayer-sdk-go/client.go @@ -297,7 +297,7 @@ func mapError(resp *Response, enterpriseFeature string) error { return &PreconditionRequiredError{newError(detail(resp.Body, "Precondition required"), sc)} case http.StatusNotImplemented: // 501 if enterpriseFeature != "" { - msg := enterpriseFeature + " requires MemoryLayer Enterprise. See https://memorylayer.ai for upgrade options." + msg := enterpriseFeature + " requires MemoryLayer Enterprise (open source, AGPL-3.0): https://github.com/scitrera/memorylayer-enterprise" return &EnterpriseRequiredError{APIError: newError(msg, sc), Feature: enterpriseFeature} } return &NotFoundError{newError(detail(resp.Body, "Not implemented"), sc)} diff --git a/memorylayer-sdk-go/client_test.go b/memorylayer-sdk-go/client_test.go index 5076d0b..49aeb4f 100644 --- a/memorylayer-sdk-go/client_test.go +++ b/memorylayer-sdk-go/client_test.go @@ -174,6 +174,20 @@ func TestTypedErrorsUnwrapToAPIError(t *testing.T) { } } +func TestEnterpriseRequiredErrorMessage(t *testing.T) { + err := mapError(&Response{StatusCode: http.StatusNotImplemented, Body: []byte(`{"detail":"nope"}`)}, "Dataset management") + var e *EnterpriseRequiredError + if !errors.As(err, &e) { + t.Fatalf("expected EnterpriseRequiredError, got %v", err) + } + if e.StatusCode != http.StatusNotImplemented || e.Feature != "Dataset management" { + t.Errorf("status=%d feature=%q", e.StatusCode, e.Feature) + } + if !strings.Contains(e.Message, "github.com/scitrera/memorylayer-enterprise") || strings.Contains(e.Message, "upgrade") { + t.Errorf("unexpected message %q", e.Message) + } +} + func TestForgetSendsHardParam(t *testing.T) { var hard string var method string diff --git a/memorylayer-sdk-python/src/memorylayer/client.py b/memorylayer-sdk-python/src/memorylayer/client.py index b8591d1..6aada02 100644 --- a/memorylayer-sdk-python/src/memorylayer/client.py +++ b/memorylayer-sdk-python/src/memorylayer/client.py @@ -385,7 +385,7 @@ async def _request( Raises: AuthenticationError: Authentication failed (401) - EnterpriseRequiredError: Enterprise-only endpoint (404 + enterprise_feature) + EnterpriseRequiredError: Enterprise-only endpoint (501 + enterprise_feature) NotFoundError: Resource not found (404) ValidationError: Validation failed (422) RateLimitError: Rate limit exceeded (429) diff --git a/memorylayer-sdk-python/src/memorylayer/exceptions.py b/memorylayer-sdk-python/src/memorylayer/exceptions.py index e1b4de3..2630b6c 100644 --- a/memorylayer-sdk-python/src/memorylayer/exceptions.py +++ b/memorylayer-sdk-python/src/memorylayer/exceptions.py @@ -32,10 +32,11 @@ def __init__(self, message: str = "Resource not found") -> None: class EnterpriseRequiredError(MemoryLayerError): - """Raised when an enterprise-only endpoint returns 404. + """Raised when an Enterprise-only endpoint returns 501 (Not Implemented). - This indicates the server is running MemoryLayer OSS which does not - include the requested feature (e.g. document ingestion, page search). + This indicates the server does not provide the requested feature (for + example dataset management), typically because the MemoryLayer Enterprise + extensions are not installed. """ def __init__( @@ -43,8 +44,8 @@ def __init__( feature: str = "This feature", message: str | None = None, ) -> None: - msg = message or (f"{feature} requires MemoryLayer Enterprise. See https://memorylayer.ai for upgrade options.") - super().__init__(msg, status_code=404) + msg = message or (f"{feature} requires MemoryLayer Enterprise (open source, AGPL-3.0): https://github.com/scitrera/memorylayer-enterprise") + super().__init__(msg, status_code=501) self.feature = feature diff --git a/memorylayer-sdk-python/src/memorylayer/sync_client.py b/memorylayer-sdk-python/src/memorylayer/sync_client.py index 7158c5f..79269fd 100644 --- a/memorylayer-sdk-python/src/memorylayer/sync_client.py +++ b/memorylayer-sdk-python/src/memorylayer/sync_client.py @@ -217,7 +217,7 @@ def _request( path: API path json: JSON body params: Query parameters - enterprise_feature: If set, a 404 raises EnterpriseRequiredError + enterprise_feature: If set, a 501 raises EnterpriseRequiredError instead of NotFoundError. Returns: @@ -225,7 +225,7 @@ def _request( Raises: AuthenticationError: Authentication failed (401) - EnterpriseRequiredError: Enterprise-only endpoint (404 + enterprise_feature) + EnterpriseRequiredError: Enterprise-only endpoint (501 + enterprise_feature) NotFoundError: Resource not found (404) ValidationError: Validation failed (422) RateLimitError: Rate limit exceeded (429) diff --git a/memorylayer-sdk-python/tests/test_phase2_surface.py b/memorylayer-sdk-python/tests/test_phase2_surface.py index f534f1d..621807a 100644 --- a/memorylayer-sdk-python/tests/test_phase2_surface.py +++ b/memorylayer-sdk-python/tests/test_phase2_surface.py @@ -221,8 +221,11 @@ async def test_entities_gated_501_raises_enterprise(client: MemoryLayerClient, b return_value=Response(501, json={"detail": "Entity registry is not enabled"}) ) async with client: - with pytest.raises(EnterpriseRequiredError): + with pytest.raises(EnterpriseRequiredError) as excinfo: await client.list_entities() + assert excinfo.value.status_code == 501 + assert "github.com/scitrera/memorylayer-enterprise" in excinfo.value.message + assert "upgrade" not in excinfo.value.message @pytest.mark.asyncio diff --git a/memorylayer-sdk-typescript/src/errors.ts b/memorylayer-sdk-typescript/src/errors.ts index 5847f4f..477f305 100644 --- a/memorylayer-sdk-typescript/src/errors.ts +++ b/memorylayer-sdk-typescript/src/errors.ts @@ -41,9 +41,10 @@ export class RateLimitError extends MemoryLayerError { } /** - * Raised when an enterprise-only endpoint returns 404. - * Indicates the server is running MemoryLayer OSS which does not - * include the requested feature (e.g. document ingestion, page search). + * Raised when an Enterprise-only endpoint returns 501 (Not Implemented). + * Indicates the server does not provide the requested feature (for example + * dataset management), typically because the MemoryLayer Enterprise + * extensions are not installed. */ export class EnterpriseRequiredError extends MemoryLayerError { constructor( @@ -52,8 +53,8 @@ export class EnterpriseRequiredError extends MemoryLayerError { ) { super( message ?? - `${feature} requires MemoryLayer Enterprise. See https://memorylayer.ai for upgrade options.`, - 404 + `${feature} requires MemoryLayer Enterprise (open source, AGPL-3.0): https://github.com/scitrera/memorylayer-enterprise`, + 501 ); this.name = "EnterpriseRequiredError"; } diff --git a/memorylayer-sdk-typescript/tests/coverage.test.ts b/memorylayer-sdk-typescript/tests/coverage.test.ts index 2898b57..efef43e 100644 --- a/memorylayer-sdk-typescript/tests/coverage.test.ts +++ b/memorylayer-sdk-typescript/tests/coverage.test.ts @@ -219,7 +219,11 @@ describe("Entity registry ops", () => { it("maps 501 to EnterpriseRequiredError when registry disabled", async () => { (global.fetch as ReturnType).mockResolvedValueOnce(mockErr(501, { detail: "registry off" })); - await expect(client.listEntities()).rejects.toBeInstanceOf(EnterpriseRequiredError); + const err = await client.listEntities().catch((e: unknown) => e); + expect(err).toBeInstanceOf(EnterpriseRequiredError); + expect((err as EnterpriseRequiredError).statusCode).toBe(501); + expect((err as EnterpriseRequiredError).message).toContain("github.com/scitrera/memorylayer-enterprise"); + expect((err as EnterpriseRequiredError).message).not.toContain("upgrade"); }); });