mwn
Version:
JavaScript & TypeScript MediaWiki bot framework for Node.js
48 lines • 1.53 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.MwnMissingPageError = exports.MwnError = void 0;
exports.rejectWithErrorCode = rejectWithErrorCode;
exports.rejectWithError = rejectWithError;
class MwnError extends Error {
/**
* @param {Object} config
*/
constructor(config) {
if (config instanceof Error) {
return config;
}
// If it's an mwn internal error, don't put the error code (begins with "mwn")
// in the error message
const code = !config.code || config.code.startsWith('mwn') ? '' : config.code + ': ';
const info = config.info || config.text || config.html || '';
super(code + info);
Object.assign(this, config);
this.info = info; // not already present in case of html/wikitext/plaintext error formats
}
}
exports.MwnError = MwnError;
class MwnMissingPageError extends MwnError {
constructor(config = {}) {
super({
code: 'missingtitle',
info: "The page you specified doesn't exist.",
...config,
});
}
}
exports.MwnMissingPageError = MwnMissingPageError;
/**
* Returns a promise rejected with an error object
* @private
* @param {string} errorCode
* @returns {Promise}
*/
function rejectWithErrorCode(errorCode) {
return rejectWithError({
code: errorCode,
});
}
function rejectWithError(errorConfig) {
return Promise.reject(new MwnError(errorConfig));
}
//# sourceMappingURL=error.js.map