mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-22 09:46:30 -05:00
AuthService.randomString: Throw Error instead of returning null
A string with a negative length is invalid, so we should throw here instead of complicating the type with a possible null return value. Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
parent
5ee9b2a7e8
commit
327f36af94
2 changed files with 7 additions and 1 deletions
|
@ -319,4 +319,10 @@ describe('AuthService', () => {
|
|||
);
|
||||
});
|
||||
});
|
||||
describe('randomString', () => {
|
||||
it('throws on invalid lenght parameter', () => {
|
||||
expect(() => service.randomString(0)).toThrow();
|
||||
expect(() => service.randomString(-1)).toThrow();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -64,7 +64,7 @@ export class AuthService {
|
|||
|
||||
randomString(length: number): Buffer {
|
||||
if (length <= 0) {
|
||||
return null;
|
||||
throw new Error('randomString cannot have a length < 1');
|
||||
}
|
||||
return randomBytes(length);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue