Errors Standardization (#1246)

* errors and stuff

* more errors

* all the errors

* fix build
This commit is contained in:
Gus Caplan
2017-06-25 12:48:05 -05:00
committed by Amish Shah
parent 602fe06f88
commit 63e54982f4
28 changed files with 258 additions and 102 deletions

View File

@@ -2,6 +2,7 @@ const EventEmitter = require('events').EventEmitter;
const secretbox = require('../util/Secretbox');
const Readable = require('./VoiceReadable');
const OpusEncoders = require('../opus/OpusEngineList');
const { Error } = require('../../../errors');
const nonce = Buffer.alloc(24);
nonce.fill(0);
@@ -122,8 +123,8 @@ class VoiceReceiver extends EventEmitter {
*/
createOpusStream(user) {
user = this.voiceConnection.voiceManager.client.resolver.resolveUser(user);
if (!user) throw new Error('Couldn\'t resolve the user to create Opus stream.');
if (this.opusStreams.get(user.id)) throw new Error('There is already an existing stream for that user.');
if (!user) throw new Error('VOICE_USER_MISSING');
if (this.opusStreams.get(user.id)) throw new Error('VOICE_STREAM_EXISTS');
const stream = new Readable();
this.opusStreams.set(user.id, stream);
return stream;
@@ -137,8 +138,8 @@ class VoiceReceiver extends EventEmitter {
*/
createPCMStream(user) {
user = this.voiceConnection.voiceManager.client.resolver.resolveUser(user);
if (!user) throw new Error('Couldn\'t resolve the user to create PCM stream.');
if (this.pcmStreams.get(user.id)) throw new Error('There is already an existing stream for that user.');
if (!user) throw new Error('VOICE_USER_MISSING');
if (this.pcmStreams.get(user.id)) throw new Error('VOICE_STREAM_EXISTS');
const stream = new Readable();
this.pcmStreams.set(user.id, stream);
return stream;