Meilisearch errors are not comparable with the instanceof operator
mmachatschek opened this issue · comments
Description
Catching erros which are produced by the meilisearch.js library can not be compared with the instanceof
operator in javascript. The only meilisearch error class that has this is MeiliSearchApiError
Expected behavior
this should work:
try {
// some code that throws an error from the meilisearch library
} catch (e if e instanceof MeiliSearchCommunicationError) {
// do something
}
// or
try {
// some code that throws an error from the meilisearch library
} catch (e) {
if (e instanceof MeiliSearchCommunicationError) {
// do some communication error fix
} else if (e instanceof MeiliSearchTimeOutError) {
// wait some time and maybe retry
}
}
Current behavior
it's only possible to use the instanceof
operator on the MeiliSearchApiError
class
try {
// some code that throws an error from the meilisearch library
} catch (e if e instanceof MeiliSearchCommunicationError) {
// this catch will never work
// do something
}
// or
try {
// some code that throws an error from the meilisearch library
} catch (e) {
// this if statement will fail
if (e instanceof MeiliSearchCommunicationError) {
}
}