UNPKG

node-hitomi

Version:
43 lines (41 loc) 1.51 kB
const ErrorCode = { InvalidArgument: 'INVALID_ARGUMENT', InvalidCombination: 'INVALID_COMBINATION', InvalidField: 'INVALID_FIELD', UnexpectedResponseStatus: 'UNEXPECTED_RESPONSE_STATUS', UnexpectedResponseBody: 'UNEXPECTED_RESPONSE_BODY' }; class HitomiError extends Error { static invalidMember(name, iteratable) { return new HitomiError(ErrorCode.InvalidArgument, name, 'one of ' + (iteratable[Symbol.iterator] ? Array.from(iteratable) : Object.values(iteratable)).join(', ')); } static unexpectedResponseStatus(host, path, code) { return new HitomiError(ErrorCode.UnexpectedResponseStatus, 'https://' + host + path + ' must not respond with ' + code); } static get unavailableExtension() { return new HitomiError(ErrorCode.InvalidCombination, 'Extension', 'available'); } static get invalidTagName() { return new HitomiError(ErrorCode.InvalidField, 'Name', 'valid'); } static get emptyRootNode() { return new HitomiError(ErrorCode.UnexpectedResponseBody, 'Root node', 'empty', false); } static get unparsableImageContext() { return new HitomiError(ErrorCode.UnexpectedResponseBody, 'Image context', 'parsable'); } constructor(code, messageOrTarget, state, isAffirmative = true) { let message = messageOrTarget; if(arguments.length !== 2) { message += ' must '; if(!isAffirmative) { message += 'not '; } message += 'be ' + state; } super(message); this.code = code; this.name = 'HitomiError [' + code + ']'; } } export { ErrorCode, HitomiError };