Skip to content

Commit

Permalink
Remove hint about bad Meilisearch version
Browse files Browse the repository at this point in the history
  • Loading branch information
flevi29 committed Jan 31, 2025
1 parent 792ce67 commit e1ed70f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 49 deletions.
1 change: 0 additions & 1 deletion src/errors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ export * from "./meilisearch-api-error.js";
export * from "./meilisearch-request-error.js";
export * from "./meilisearch-error.js";
export * from "./meilisearch-timeout-error.js";
export * from "./version-hint-message.js";
3 changes: 0 additions & 3 deletions src/errors/version-hint-message.ts

This file was deleted.

44 changes: 10 additions & 34 deletions src/indexes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@
* Copyright: 2019, MeiliSearch
*/

import {
MeiliSearchError,
MeiliSearchRequestError,
versionErrorHintMessage,
MeiliSearchApiError,
} from "./errors/index.js";
import { MeiliSearchError } from "./errors/index.js";
import type {
Config,
SearchResponse,
Expand Down Expand Up @@ -373,22 +368,13 @@ class Index<T extends Record<string, any> = Record<string, any>> {

// In case `filter` is provided, use `POST /documents/fetch`
if (parameters.filter !== undefined) {
try {
const url = `indexes/${this.uid}/documents/fetch`;

return await this.httpRequest.post<
DocumentsQuery,
Promise<ResourceResults<D[]>>
>(url, parameters);
} catch (e) {
if (e instanceof MeiliSearchRequestError) {
e.message = versionErrorHintMessage(e.message, "getDocuments");
} else if (e instanceof MeiliSearchApiError) {
e.message = versionErrorHintMessage(e.message, "getDocuments");
}

throw e;
}
const url = `indexes/${this.uid}/documents/fetch`;

return await this.httpRequest.post<
DocumentsQuery,
Promise<ResourceResults<D[]>>
>(url, parameters);

// Else use `GET /documents` method
} else {
const url = `indexes/${this.uid}/documents`;
Expand Down Expand Up @@ -601,19 +587,9 @@ class Index<T extends Record<string, any> = Record<string, any>> {
: "documents/delete-batch";
const url = `indexes/${this.uid}/${endpoint}`;

try {
const task = await this.httpRequest.post(url, params);
const task = await this.httpRequest.post(url, params);

return new EnqueuedTask(task);
} catch (e) {
if (e instanceof MeiliSearchRequestError && isDocumentsDeletionQuery) {
e.message = versionErrorHintMessage(e.message, "deleteDocuments");
} else if (e instanceof MeiliSearchApiError) {
e.message = versionErrorHintMessage(e.message, "deleteDocuments");
}

throw e;
}
return new EnqueuedTask(task);
}

/**
Expand Down
15 changes: 4 additions & 11 deletions tests/documents.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,7 @@ describe("Documents tests", () => {
"getDocuments should have raised an error when the route does not exist",
);
} catch (e: any) {
expect(e.message).toEqual(
"404: Not Found\nHint: It might not be working because maybe you're not up to date with the Meilisearch version that getDocuments call requires.",
);
expect(e.message).toEqual("404: Not Found");
}
});

Expand All @@ -191,8 +189,7 @@ describe("Documents tests", () => {
} catch (e: any) {
expect(e.message).toEqual(
`Attribute \`id\` is not filterable. This index does not have configured filterable attributes.
1:3 id = 1
Hint: It might not be working because maybe you're not up to date with the Meilisearch version that getDocuments call requires.`,
1:3 id = 1`,
);
}
});
Expand Down Expand Up @@ -663,9 +660,7 @@ Hint: It might not be working because maybe you're not up to date with the Meili
"deleteDocuments should have raised an error when the parameters are wrong",
);
} catch (e: any) {
expect(e.message).toEqual(
"Sending an empty filter is forbidden.\nHint: It might not be working because maybe you're not up to date with the Meilisearch version that deleteDocuments call requires.",
);
expect(e.message).toEqual("Sending an empty filter is forbidden.");
}
});

Expand All @@ -680,9 +675,7 @@ Hint: It might not be working because maybe you're not up to date with the Meili
"deleteDocuments should have raised an error when the route does not exist",
);
} catch (e: any) {
expect(e.message).toEqual(
"404: Not Found\nHint: It might not be working because maybe you're not up to date with the Meilisearch version that deleteDocuments call requires.",
);
expect(e.message).toEqual("404: Not Found");
}
});

Expand Down

0 comments on commit e1ed70f

Please sign in to comment.