No throwing literals 2

This commit is contained in:
Adhiraj
2020-07-10 21:31:29 +05:30
parent e7355f5ca3
commit 5f54a9443c
2 changed files with 9 additions and 9 deletions

View File

@@ -44,7 +44,7 @@ export default class WhatsAppWebMessages extends WhatsAppWebBase {
async modifyChat (jid: string, type: ChatModification, options: {stamp: Date | string} = {stamp: new Date()}) {
let chatAttrs: Record<string, string> = {jid: jid}
if ((type === ChatModification.unpin || type === ChatModification.unmute) && !options?.stamp) {
throw 'options.stamp must be set to the timestamp of the time of pinning/unpinning of the chat'
throw new Error('options.stamp must be set to the timestamp of the time of pinning/unpinning of the chat')
}
const strStamp = options.stamp &&
(typeof options.stamp === 'string' ? options.stamp : Math.round(options.stamp.getTime ()/1000).toString ())
@@ -132,7 +132,7 @@ export default class WhatsAppWebMessages extends WhatsAppWebBase {
case MessageType.text:
case MessageType.extendedText:
if (typeof message !== 'string') {
throw 'expected message to be a string'
throw new Error('expected message to be a string')
}
m.extendedTextMessage = { text: message }
break
@@ -152,10 +152,10 @@ export default class WhatsAppWebMessages extends WhatsAppWebBase {
/** Prepare a media message for sending */
protected async prepareMediaMessage(buffer: Buffer, mediaType: MessageType, options: MessageOptions = {}) {
if (mediaType === MessageType.document && !options.mimetype) {
throw 'mimetype required to send a document'
throw new Error('mimetype required to send a document')
}
if (mediaType === MessageType.sticker && options.caption) {
throw 'cannot send a caption with a sticker'
throw new Error('cannot send a caption with a sticker')
}
if (!options.mimetype) {
options.mimetype = MimetypeMap[mediaType]
@@ -195,7 +195,7 @@ export default class WhatsAppWebMessages extends WhatsAppWebBase {
})
const responseJSON = await urlFetch.json()
if (!responseJSON.url) {
throw 'UPLOAD FAILED GOT: ' + JSON.stringify(responseJSON)
throw new Error('Upload failed got: ' + JSON.stringify(responseJSON))
}
const message = {}
message[mediaType] = {

View File

@@ -63,7 +63,7 @@ export async function generateThumbnail(buffer: Buffer, mediaType: MessageType,
if (info.thumbnail === null || info.thumbnail) {
// don't do anything if the thumbnail is already provided, or is null
if (mediaType === MessageType.audio) {
throw 'audio messages cannot have thumbnails'
throw new Error('audio messages cannot have thumbnails')
}
} else if (mediaType === MessageType.image || mediaType === MessageType.sticker) {
const buff = await sharp(buffer).resize(48, 48).jpeg().toBuffer()
@@ -97,10 +97,10 @@ export async function decodeMediaMessage(message: WAMessageContent, filename: st
*/
const type = Object.keys(message)[0] as MessageType
if (!type) {
throw 'unknown message type'
throw new Error('unknown message type')
}
if (type === MessageType.text || type === MessageType.extendedText) {
throw 'cannot decode text message'
throw new Error('cannot decode text message')
}
if (type === MessageType.location || type === MessageType.liveLocation) {
fs.writeFileSync(filename + '.jpeg', message[type].jpegThumbnail)
@@ -138,6 +138,6 @@ export async function decodeMediaMessage(message: WAMessageContent, filename: st
return trueFileName
} else {
throw 'HMAC sign does not match'
throw new Error('HMAC sign does not match')
}
}