used await instead of .then().catch() (KhaaZ)
parent
b9f789e628
commit
cd86c3f7ee
|
@ -2,7 +2,7 @@ import { Message } from 'eris';
|
|||
import axios from 'axios';
|
||||
import { Client, Command, RichEmbed } from '../class';
|
||||
|
||||
export default class Mdn extends Command {
|
||||
export default class MDN extends Command {
|
||||
constructor(client: Client) {
|
||||
super(client);
|
||||
this.name = 'mdn';
|
||||
|
@ -20,10 +20,15 @@ export default class Mdn extends Command {
|
|||
args[0] = args[0].replace('.', '.prototype.');
|
||||
args[0] = args[0].replace('#', '.prototype.');
|
||||
|
||||
return axios.get(`https://mdn.pleb.xyz/search?q=${args[0]}`)
|
||||
.then((res) => {
|
||||
let res;
|
||||
try {
|
||||
res = await axios.get(`https://mdn.pleb.xyz/search?q=${args[0]}`);
|
||||
} catch (err) {
|
||||
this.error(message.channel, 'Please try again later, something unexpected happened.');
|
||||
return this.client.util.handleError(err, message, this);
|
||||
}
|
||||
const { data } = res;
|
||||
if (!data.Title || !data.Summary || !data.URL) return this.error(message.channel, 'Could not find information. Try something else.');
|
||||
if (!data || !data.Title || !data.Summary || !data.URL) return this.error(message.channel, 'Could not find information. Try something else.');
|
||||
|
||||
// Do not touch to the next block of code. Don't even look at it. your brain could stop working
|
||||
data.Summary = data.Summary.replace(/<code><strong>/g, '<strong><code>');
|
||||
|
@ -55,11 +60,6 @@ export default class Mdn extends Command {
|
|||
embed.setTimestamp();
|
||||
|
||||
return message.channel.createMessage({ embed });
|
||||
})
|
||||
.catch((err) => {
|
||||
this.error(message.channel, 'Please try again later, something unexpected happened.');
|
||||
this.client.util.handleError(err, message, this);
|
||||
});
|
||||
} catch (err) {
|
||||
return this.client.util.handleError(err, message, this);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue