{"version":3,"file":"error-utils.mjs","names":[],"sources":["../src/error-utils.ts"],"sourcesContent":["import type { HttpError } from 'http-errors';\nimport createError from 'http-errors';\n\nimport { HTTP_STATUS } from './constants';\n\nexport const API_ERROR = {\n  PASSWORD_SHORT: 'The provided password does not pass the validation',\n  MUST_BE_LOGGED: 'You must be logged in to publish packages.',\n  PLUGIN_ERROR: 'bug in the auth plugin system',\n  CONFIG_BAD_FORMAT: 'config file must be an object',\n  BAD_USERNAME_PASSWORD: 'bad username/password, access denied',\n  NO_PACKAGE: 'no such package available',\n  PACKAGE_CANNOT_BE_ADDED: 'this package cannot be added',\n  BAD_DATA: 'bad data',\n  NOT_ALLOWED: 'not allowed to access package',\n  NOT_ALLOWED_PUBLISH: 'not allowed to publish package',\n  INTERNAL_SERVER_ERROR: 'internal server error',\n  UNKNOWN_ERROR: 'unknown error',\n  NOT_PACKAGE_UPLINK: 'package does not exist on uplink',\n  UPLINK_OFFLINE_PUBLISH: 'one of the uplinks is down, refuse to publish',\n  UPLINK_OFFLINE: 'uplink is offline',\n  NOT_MODIFIED_NO_DATA: 'no data',\n  CONTENT_MISMATCH: 'content length mismatch',\n  NOT_FILE_UPLINK: \"file doesn't exist on uplink\",\n  MAX_USERS_REACHED: 'maximum amount of users reached',\n  VERSION_NOT_EXIST: \"this version doesn't exist\",\n  NO_SUCH_FILE: 'no such file available',\n  UNSUPORTED_REGISTRY_CALL: 'unsupported registry call',\n  FILE_NOT_FOUND: 'File not found',\n  REGISTRATION_DISABLED: 'user registration disabled',\n  UNAUTHORIZED_ACCESS: 'unauthorized access',\n  BAD_STATUS_CODE: 'bad status code',\n  SERVER_TIME_OUT: 'looks like the server is taking to long to respond',\n  PACKAGE_EXIST: 'this package is already present',\n  BAD_AUTH_HEADER: 'bad authorization header',\n  WEB_DISABLED: 'Web interface is disabled in the config file',\n  DEPRECATED_BASIC_HEADER: 'basic authentication is deprecated, please use JWT instead',\n  BAD_FORMAT_USER_GROUP: 'user groups is different than an array',\n  RESOURCE_UNAVAILABLE: 'resource unavailable',\n  BAD_PACKAGE_DATA: 'bad incoming package data',\n  USERNAME_PASSWORD_REQUIRED: 'username and password is required',\n  USERNAME_ALREADY_REGISTERED: 'username is already registered',\n  USERNAME_MISMATCH: 'username does not match logged in user',\n  SESSION_ID_REQUIRED: 'session id is required',\n  SESSION_ID_INVALID: 'session id is invalid',\n  SESSION_TOKEN_EXPIRED: 'session token expired',\n};\n\nexport const SUPPORT_ERRORS = {\n  PLUGIN_MISSING_INTERFACE: 'the plugin does not provide implementation of the requested feature',\n  TFA_DISABLED: 'the two-factor authentication is not yet supported',\n  STORAGE_NOT_IMPLEMENT: 'the storage does not support token saving',\n  PARAMETERS_NOT_VALID: 'the parameters are not valid',\n};\n\nexport const APP_ERROR = {\n  CONFIG_NOT_VALID: 'CONFIG: it does not look like a valid config file',\n  PROFILE_ERROR: 'profile unexpected error',\n  PASSWORD_VALIDATION: 'not valid password',\n};\n\nexport type VerdaccioError = HttpError & { code: number };\n\nfunction getError(code: number, message: string): VerdaccioError {\n  const httpError = createError(code, message);\n\n  httpError.code = code;\n\n  return httpError as VerdaccioError;\n}\n\nexport function getConflict(message: string = API_ERROR.PACKAGE_EXIST): VerdaccioError {\n  return getError(HTTP_STATUS.CONFLICT, message);\n}\n\nexport function getBadData(customMessage?: string): VerdaccioError {\n  return getError(HTTP_STATUS.BAD_DATA, customMessage || API_ERROR.BAD_DATA);\n}\n\nexport function getBadRequest(customMessage: string): VerdaccioError {\n  return getError(HTTP_STATUS.BAD_REQUEST, customMessage);\n}\n\nexport function getInternalError(customMessage?: string): VerdaccioError {\n  return customMessage\n    ? getError(HTTP_STATUS.INTERNAL_ERROR, customMessage)\n    : getError(HTTP_STATUS.INTERNAL_ERROR, API_ERROR.UNKNOWN_ERROR);\n}\n\nexport function getUnauthorized(message = 'no credentials provided'): VerdaccioError {\n  return getError(HTTP_STATUS.UNAUTHORIZED, message);\n}\n\nexport function getForbidden(message = \"can't use this filename\"): VerdaccioError {\n  return getError(HTTP_STATUS.FORBIDDEN, message);\n}\n\nexport function getServiceUnavailable(\n  message: string = API_ERROR.RESOURCE_UNAVAILABLE\n): VerdaccioError {\n  return getError(HTTP_STATUS.SERVICE_UNAVAILABLE, message);\n}\n\nexport function getNotFound(customMessage?: string): VerdaccioError {\n  return getError(HTTP_STATUS.NOT_FOUND, customMessage || API_ERROR.NO_PACKAGE);\n}\n\nexport function getCode(statusCode: number, customMessage: string): VerdaccioError {\n  return getError(statusCode, customMessage);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAKA,IAAa,YAAY;CACvB,gBAAgB;CAChB,gBAAgB;CAChB,cAAc;CACd,mBAAmB;CACnB,uBAAuB;CACvB,YAAY;CACZ,yBAAyB;CACzB,UAAU;CACV,aAAa;CACb,qBAAqB;CACrB,uBAAuB;CACvB,eAAe;CACf,oBAAoB;CACpB,wBAAwB;CACxB,gBAAgB;CAChB,sBAAsB;CACtB,kBAAkB;CAClB,iBAAiB;CACjB,mBAAmB;CACnB,mBAAmB;CACnB,cAAc;CACd,0BAA0B;CAC1B,gBAAgB;CAChB,uBAAuB;CACvB,qBAAqB;CACrB,iBAAiB;CACjB,iBAAiB;CACjB,eAAe;CACf,iBAAiB;CACjB,cAAc;CACd,yBAAyB;CACzB,uBAAuB;CACvB,sBAAsB;CACtB,kBAAkB;CAClB,4BAA4B;CAC5B,6BAA6B;CAC7B,mBAAmB;CACnB,qBAAqB;CACrB,oBAAoB;CACpB,uBAAuB;AACzB;AAEA,IAAa,iBAAiB;CAC5B,0BAA0B;CAC1B,cAAc;CACd,uBAAuB;CACvB,sBAAsB;AACxB;AAEA,IAAa,YAAY;CACvB,kBAAkB;CAClB,eAAe;CACf,qBAAqB;AACvB;AAIA,SAAS,SAAS,MAAc,SAAiC;CAC/D,MAAM,YAAY,YAAY,MAAM,OAAO;CAE3C,UAAU,OAAO;CAEjB,OAAO;AACT;AAEA,SAAgB,YAAY,UAAkB,UAAU,eAA+B;CACrF,OAAO,SAAS,YA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