6.0.0) partial rewrite
Done: Removed node-fetch as a dependency Simplified flow Modularized things
Todo: Rewite documentation. Port social features. A ton of bug testing.
Let me check later - I can take a look this evening
I like that the naming is much clearer now!
Another thing I thought of is that the errors should maybe be written out in place but have a second property for the translation string, so that there is a default explanation. So that there maybe is a mother error type and all other errors extend that, that mother error class also handles the translation fetching.
Maybe something like this (only poc):
export class MSMCError extends Error {
public readonly translationKey: string;
constructor(message: string, translationKey: string) {
// Look up the key in the map; if undefined or empty, fall back to the provided message
const resolvedMessage = translationMap[translationKey] || message;
super(resolvedMessage);
this.name = 'MSMCError';
this.translationKey = translationKey;
// Set the prototype explicitly to ensure 'instanceof' works correctly,
// especially if you are compiling down to ES5.
Object.setPrototypeOf(this, MSMCError.prototype);
// Maintains proper stack trace for where our error was thrown (V8 environments like Node.js / Chrome)
if (Error.captureStackTrace) {
Error.captureStackTrace(this, MSMCError);
}
}
}
There are also some other conventions on custom js errors in here that I didnt know of myself..