0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2025-03-18 02:22:46 -05:00

refactor: add new constants

This commit is contained in:
Juan Picado @jotadeveloper 2018-06-30 17:13:53 +02:00
parent 2e157fb134
commit 050f857fb6
No known key found for this signature in database
GPG key ID: 18AC54485952D158
5 changed files with 15 additions and 10 deletions

View file

@ -32,6 +32,7 @@
"rules": {
"no-useless-escape": 2,
"react/no-deprecated": 1,
"react/jsx-no-target-blank": 1,
"handle-callback-err": 2,
"no-fallthrough": 2,
"no-new-require": 2,

View file

@ -8,7 +8,7 @@ import {aesDecrypt, aesEncrypt, signPayload, verifyPayload} from './crypto-utils
import type {Config, Logger, Callback} from '@verdaccio/types';
import type {$Response, NextFunction} from 'express';
import type {$RequestExtend, JWTPayload} from '../../types';
import {ROLES} from './constants';
import {API_ERROR, ROLES} from './constants';
const LoggerApi = require('./logger');
@ -63,11 +63,11 @@ class Auth {
this.plugins.push({
authenticate: function(user, password, cb) {
cb(ErrorCode.getForbidden('bad username/password, access denied'));
cb(ErrorCode.getForbidden(API_ERROR.BAD_USERNAME_PASSWORD));
},
add_user: function(user, password, cb) {
return cb(ErrorCode.getConflict('bad username/password, access denied'));
return cb(ErrorCode.getConflict(API_ERROR.BAD_USERNAME_PASSWORD));
},
allow_access: allow_action('access'),

View file

@ -65,17 +65,20 @@ export const API_MESSAGE = {
};
export const API_ERROR = {
BAD_USERNAME_PASSWORD: 'bad username/password, access denied {APP}',
NO_PACKAGE: 'no such package available',
NOT_ALLOWED: 'not allowed to access package',
INTERNAL_SERVER_ERROR: 'internal server error',
UNKNOWN_ERROR: 'unknown error',
NOT_PACKAGE_UPLINK: 'package does not exist on uplink',
UPLINK_OFFLINE: 'one of the uplinks is down, refuse to publish',
CONTENT_MISMATCH: 'content length mismatch',
NOT_FILE_UPLINK: 'file doesn\'t exist on uplink',
MAX_USERS_REACHED: 'maximum amount of users reached',
VERSION_NOT_EXIST: 'this version doesn\'t exist',
FILE_NOT_FOUND: 'File not found',
BAD_STATUS_CODE: 'bad status code',
PACKAGE_EXIST: 'this package is already present',
WEB_DISABLED: 'Web interface is disabled in the config file',
};

View file

@ -7,6 +7,7 @@ import {generateRandomHexString} from '../lib/crypto-utils';
import type {Package, Version} from '@verdaccio/types';
import type {IStorage} from '../../types';
import {API_ERROR, HTTP_STATUS} from './constants';
const pkgFileName = 'package.json';
const fileExist: string = 'EEXISTS';
@ -123,11 +124,11 @@ export function cleanUpLinksRef(keepUpLinkData: boolean, result: Package): Packa
export function checkPackageLocal(name: string, localStorage: IStorage): Promise<any> {
return new Promise((resolve, reject) => {
localStorage.getPackageMetadata(name, (err, results) => {
if (!_.isNil(err) && err.status !== 404) {
if (!_.isNil(err) && err.status !== HTTP_STATUS.NOT_FOUND) {
return reject(err);
}
if (results) {
return reject(ErrorCode.getConflict('this package is already present'));
return reject(ErrorCode.getConflict(API_ERROR.PACKAGE_EXIST));
}
return resolve();
});
@ -152,25 +153,25 @@ export function checkPackageRemote(name: string, isAllowPublishOffline: boolean,
// $FlowFixMe
syncMetadata(name, null, {}, (err, packageJsonLocal, upLinksErrors) => {
// something weird
if (err && err.status !== 404) {
if (err && err.status !== HTTP_STATUS.NOT_FOUND) {
return reject(err);
}
// checking package exist already
if (_.isNil(packageJsonLocal) === false) {
return reject(ErrorCode.getConflict('this package is already present'));
return reject(ErrorCode.getConflict(API_ERROR.PACKAGE_EXIST));
}
for (let errorItem = 0; errorItem < upLinksErrors.length; errorItem++) {
// checking error
// if uplink fails with a status other than 404, we report failure
if (_.isNil(upLinksErrors[errorItem][0]) === false) {
if (upLinksErrors[errorItem][0].status !== 404) {
if (upLinksErrors[errorItem][0].status !== HTTP_STATUS.NOT_FOUND) {
if (isAllowPublishOffline) {
return resolve();
}
return reject(ErrorCode.getServiceUnavailable('one of the uplinks is down, refuse to publish'));
return reject(ErrorCode.getServiceUnavailable(API_ERROR.UPLINK_OFFLINE));
}
}
}

View file

@ -29,7 +29,7 @@ describe('endpoint unit test', () => {
const configForTest = _.clone(configDefault);
configForTest.auth = {
htpasswd: {
file: './test-storage/htpasswd-test'
file: './test-storage/.htpasswd'
}
};
configForTest.uplinks = {