I am working on express backend app with Mongoose as ODM. I just want to know if is there any built-in way to import the error codes/types so that we compare or use it something like below code snippet.
import { WriteConflict } from 'mongodb'
if (errorCode === WriteConflict) {
// do someting
}
Instead of using magic number (error code)
``
if (errorCode === 112) {
// do someting
}
or creating a new file in our code base manually and use that across application like below (not preferred, if there is any way to import directly from the MongoDB library);
eg: mongodb.error.ts file
```export const MONGODB_ERROR_CODES = {
HostUnreachable: 6,
HostNotFound: 7,
AuthenticationFailed: 18,
NetworkTimeout: 89,
ShutdownInProgress: 91,
PrimarySteppedDown: 189,
ExceededTimeLimit: 262,
SocketException: 9001,
...
...
} as const satisfies Record<string, number>;