Skip to content

Commit

Permalink
Show the command used when an error occur
Browse files Browse the repository at this point in the history
  • Loading branch information
sampaiodiego committed Jan 7, 2020
1 parent 47362b3 commit b24713d
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/PollCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { IPoll } from './IPoll';

const clearQuotes = (item) => item.replace(/(^['"]|['"]$)/g, '');

const avatarURL = 'https://user-images.githubusercontent.com/8591547/44113440-751b9ff8-9fde-11e8-9e8c-8a555e6e382b.png';

export class PollCommand implements ISlashCommand {

public command = 'poll';
Expand All @@ -30,7 +32,7 @@ export class PollCommand implements ISlashCommand {
const builder = modify.getCreator().startMessage()
.setSender(context.getSender())
.setRoom(context.getRoom())
.setAvatarUrl('https://user-images.githubusercontent.com/8591547/44113440-751b9ff8-9fde-11e8-9e8c-8a555e6e382b.png')
.setAvatarUrl(avatarURL)
.setText(`_${question}_`)
.setUsernameAlias('Poll');

Expand Down Expand Up @@ -62,8 +64,18 @@ export class PollCommand implements ISlashCommand {
const association = new RocketChatAssociationRecord(RocketChatAssociationModel.MISC, UUID);
await persis.createWithAssociation(poll, association);
} catch (e) {

builder.setText('An error occured when trying to send the gif :disappointed_relieved:');
const errorText = `An error occured when trying to create the poll :disappointed_relieved:
Command executed:
\`\`\`
/poll ${ params }
\`\`\``;
const builder = modify.getCreator().startMessage()
.setSender(context.getSender())
.setRoom(context.getRoom())
.setAvatarUrl(avatarURL)
.setText(errorText)
.setUsernameAlias('Poll');

modify.getNotifier().notifyUser(context.getSender(), builder.getMessage());
}
Expand Down

0 comments on commit b24713d

Please sign in to comment.