Skip to content

Commit

Permalink
update warning errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Dustin Blackman committed Jun 27, 2016
1 parent 61980b3 commit c82f838
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/commands/games/leagueoflegends/championgg.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import T from '../../../translate';
const request = Promise.promisify(_request);

// Error instances
const Warning = SuperError.subclass('NoPosition', function(msg) {
const Warning = SuperError.subclass('Warning', function(msg) {
this.message = msg || 'Not Found';
this.code = 404;
this.level = 'warning';
Expand Down
10 changes: 8 additions & 2 deletions src/commands/games/leagueoflegends/riot.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ const NotYetAvailable = SuperError.subclass('NotYetAvailable', function(msg) {
this.level = 'warning';
});

const Warning = SuperError.subclass('Warning', function(msg) {
this.message = msg || 'Not Found';
this.code = 404;
this.level = 'warning';
});

// List of regions
const regions = ['br', 'eune', 'euw', 'kr', 'lan', 'las', 'na', 'oce', 'ru', 'tr'];

Expand Down Expand Up @@ -90,7 +96,7 @@ function _getMatchSummoners(region, name, summoner_id) {
})
.catch(NotFoundError, err => {
console.error(err);
throw new Error(`**${name}** isn't in a game.`);
throw new Warning(`**${name}** isn't in a game.`);
});
}

Expand Down Expand Up @@ -173,7 +179,7 @@ export function matchDetails(client, evt, suffix, lang) {
return _makeRequest(`https://${region}.api.pvp.net/api/lol/${region}/v1.4/summoner/by-name/${name}`)
.catch(NotFoundError, err => {
console.error(err);
throw new Error(`I can't find **${name}** in the **${region}** region.`);
throw new Warning(`I can't find **${name}** in the **${region}** region.`);
})
.then(R.values)
.then(R.nth(0))
Expand Down
10 changes: 8 additions & 2 deletions src/commands/games/overwatch/blizzard.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@ import Promise from 'bluebird';
import cheerio from 'cheerio';
import { remove as removeDiacritics } from 'diacritics';
import R from 'ramda';
import SuperError from 'super-error';

import phantom from '../../../phantom';

const request = Promise.promisify(require('request'));

const Warning = SuperError.subclass('Warning', function(msg) {
this.message = msg || 'Not Found';
this.code = 404;
this.level = 'warning';
});

function _getRegion(battletag) {
return Promise.filter(['eu', 'us', 'cn', 'kr'], region => {
Expand All @@ -28,12 +34,12 @@ function _getRegion(battletag) {
function _makeRequest(player_name, region) {
const battletag = player_name.replace(/#/g, '-');
if (R.last(battletag.split('-')).replace(/[0-9]/g, '').length !== 0) {
return Promise.reject(new Error(`**${player_name}** isn't a valid Battletag. It requires your username and number that can be found in your blizzard client. E.g. **PlayerName#1234**`));
return Promise.reject(new Warning(`**${player_name}** isn't a valid Battletag. It requires your username and number that can be found in your blizzard client. E.g. **PlayerName#1234**`));
}

let region_promise = Promise.resolve(region);
if (!region) region_promise = _getRegion(battletag);
const notfounderror = new Error(`Couldn't find battletag ${player_name}. Remember that battletags are case sensitive.`);
const notfounderror = new Warning(`Couldn't find battletag ${player_name}. Remember that battletags are case sensitive.`);

return region_promise.then(region => {
if (!region) throw notfounderror;
Expand Down

0 comments on commit c82f838

Please sign in to comment.