Skip to content

Commit e28f4f5

Browse files
committed
Update errors in Update response
1 parent 3a2bb7b commit e28f4f5

File tree

3 files changed

+30
-33
lines changed

3 files changed

+30
-33
lines changed

src/errors/meilisearch-api-error.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
1-
import {
2-
MSApiError,
3-
MeiliSearchApiErrorResponse,
4-
MSApiErrorConstructor,
5-
} from '../types'
1+
import { MeiliSearchErrorInterface } from '../types'
62

7-
const MeiliSearchApiError: MSApiErrorConstructor = class
8-
extends Error
9-
implements MSApiError {
3+
const MeiliSearchApiError = class extends Error {
104
httpStatus: number
11-
response?: MeiliSearchApiErrorResponse
125
code?: string
136
link?: string
147
stack?: string
158
type?: string
169

17-
constructor(error: MSApiError, status: number) {
10+
constructor(error: MeiliSearchErrorInterface, status: number) {
1811
super(error.message)
1912
this.name = 'MeiliSearchApiError'
2013

src/types/types.ts

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ export type Update = {
174174
duration: number
175175
enqueuedAt: string
176176
processedAt: string
177+
error?: MeiliSearchErrorBody
177178
}
178179

179180
export type EnqueuedDump = {
@@ -236,22 +237,11 @@ export type Version = {
236237
** ERROR HANDLER
237238
*/
238239

239-
export type MSApiErrorConstructor = new (
240-
error: MSApiError,
241-
status: number
242-
) => void
243-
244-
export type MeiliSearchApiErrorResponse = {
245-
status?: number
246-
statusText?: string
247-
path?: string
248-
method?: string
249-
body?: object
250-
}
251-
export type MeiliSearchApiErrorRequest = {
252-
url?: string
253-
path?: string
254-
method?: string
240+
export interface MeiliSearchErrorInterface extends Error {
241+
code?: string
242+
link?: string
243+
stack?: string
244+
type?: string
255245
}
256246

257247
export interface FetchError extends Error {
@@ -260,14 +250,11 @@ export interface FetchError extends Error {
260250
code: string
261251
}
262252

263-
export interface MSApiError extends Error {
264-
name: string
253+
export type MeiliSearchErrorBody = {
254+
code: string
255+
link: string
265256
message: string
266-
stack?: string
267-
httpStatus: number
268-
code?: string
269-
type?: string
270-
link?: string
257+
type: string
271258
}
272259

273260
export const enum ErrorStatusCode {

tests/documents_tests.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,23 @@ describe.each([
369369
expect(response).toHaveProperty('primaryKey', 'unique')
370370
})
371371

372+
test(`${permission} key: Add a document without a primary key and check response in update status`, async () => {
373+
const docs = [
374+
{
375+
title: 'Le Rouge et le Noir',
376+
},
377+
]
378+
const { updateId } = await client.index(indexNoPk.uid).addDocuments(docs)
379+
380+
const { error } = await client
381+
.index(indexNoPk.uid)
382+
.waitForPendingUpdate(updateId)
383+
expect(error).toHaveProperty('code')
384+
expect(error).toHaveProperty('link')
385+
expect(error).toHaveProperty('message')
386+
expect(error).toHaveProperty('type')
387+
})
388+
372389
test(`${permission} key: Try to add documents from index with no primary key with NO valid primary key, update should fail`, async () => {
373390
const { updateId } = await client.index(indexNoPk.uid).addDocuments([
374391
{

0 commit comments

Comments
 (0)