utility.linvite: better error handling
This commit is contained in:
		
							parent
							
								
									db56f114ac
								
							
						
					
					
						commit
						5a5c38e6d5
					
				
					 1 changed files with 25 additions and 4 deletions
				
			
		| 
						 | 
				
			
			@ -59,7 +59,12 @@ const CUSTOM_EMOTE_REGEX = /<(?:\u200b|&)?(a)?:(\w+):(\d+)>/;
 | 
			
		|||
 | 
			
		||||
const sharp = require("sharp");
 | 
			
		||||
 | 
			
		||||
const {hastebin, lookupUser, formatTime} = require("../lib/utils.js");
 | 
			
		||||
const {
 | 
			
		||||
  hastebin,
 | 
			
		||||
  lookupUser,
 | 
			
		||||
  formatTime,
 | 
			
		||||
  safeString,
 | 
			
		||||
} = require("../lib/utils.js");
 | 
			
		||||
const {getNamesFromString} = require("../lib/unicode.js");
 | 
			
		||||
 | 
			
		||||
const avatar = new Command("avatar");
 | 
			
		||||
| 
						 | 
				
			
			@ -278,9 +283,25 @@ lookupinvite.callback = async function (msg, line) {
 | 
			
		|||
 | 
			
		||||
  line = line.replace(/(https?:\/\/)?discord\.gg\//, "");
 | 
			
		||||
 | 
			
		||||
  const invite = await hf.bot.requestHandler.request("GET",
 | 
			
		||||
    `/invites/${line}?with_counts=1`,
 | 
			
		||||
  );
 | 
			
		||||
  let bail = false;
 | 
			
		||||
  let error;
 | 
			
		||||
  let invite;
 | 
			
		||||
  try {
 | 
			
		||||
    invite = await hf.bot.requestHandler.request(
 | 
			
		||||
      "GET",
 | 
			
		||||
      `/invites/${line}?with_counts=1`
 | 
			
		||||
    );
 | 
			
		||||
  } catch (err) {
 | 
			
		||||
    bail = true;
 | 
			
		||||
    error = err;
 | 
			
		||||
  }
 | 
			
		||||
  if (bail && error) {
 | 
			
		||||
    if (error.message.includes("Unknown Invite")) {
 | 
			
		||||
      return "Invite provided is not valid.";
 | 
			
		||||
    } else {
 | 
			
		||||
      return `:warning: Got error \`${safeString(error)}\``;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  if (!invite) return ":warning: No data returned.";
 | 
			
		||||
 | 
			
		||||
  if (invite.message) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue