fix(server): handle PasswordConflict explicitly to avoid a 500 (#1536)

This commit is contained in:
Sander Bruens 2024-04-17 17:55:08 -04:00 committed by GitHub
parent 5bd4647414
commit be0d3b3838
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 14 additions and 2 deletions

View file

@ -532,7 +532,16 @@ describe('ShadowsocksManagerService', () => {
done();
});
});
it('rejects a password that is already in use', async (done) => {
const PASSWORD = 'foobar';
await repo.createNewAccessKey({password: PASSWORD});
const res = {send: SEND_NOTHING};
await serviceMethod({params: {id: accessKeyId, password: PASSWORD}}, res, (error) => {
expect(error.statusCode).toEqual(409);
responseProcessed = true; // required for afterEach to pass.
done();
});
});
it('uses the default port for new keys when no port is provided', async (done) => {
const res = {
send: (httpCode, data) => {

View file

@ -383,7 +383,10 @@ export class ShadowsocksManagerService {
logging.error(error);
if (error instanceof errors.InvalidCipher || error instanceof errors.InvalidPortNumber) {
throw new restifyErrors.InvalidArgumentError({statusCode: 400}, error.message);
} else if (error instanceof errors.PortUnavailable) {
} else if (
error instanceof errors.PortUnavailable ||
error instanceof errors.PasswordConflict
) {
throw new restifyErrors.ConflictError(error.message);
}
throw error;