Return Exception instead of plain error string

[ci skip]
This commit is contained in:
Szymon Uglis 2020-06-27 23:21:13 +02:00
parent 4606f45a66
commit 3f4679764b
7 changed files with 12 additions and 12 deletions

View file

@ -304,7 +304,7 @@ class Nyxx implements Disposable {
/// ```
Future<Guild> createGuild(GuildBuilder builder) async {
if (this.guilds.count >= 10) {
return Future.error("Guild cannot be created if bot is in 10 or more guilds");
return Future.error(ArgumentError("Guild cannot be created if bot is in 10 or more guilds"));
}
final response = await this._http._execute(BasicRequest._new("/guilds", method: "POST"));

View file

@ -120,7 +120,7 @@ abstract class MessageChannel implements Channel, ISend, Disposable {
if (files != null && files.isNotEmpty) {
for (final file in files) {
if (file._bytes.length > fileUploadLimit) {
return Future.error("File with name: [${file._name}] is too big!");
return Future.error(ArgumentError("File with name: [${file._name}] is too big!"));
}
}

View file

@ -114,7 +114,7 @@ abstract class CachelessGuildChannel extends IGuildChannel {
@override
Future<void> editChannelPermissions(PermissionsBuilder perms, SnowflakeEntity entity, {String? auditReason}) async {
if (entity is! IRole && entity is! User) {
return Future.error(Exception("The `id` property must be either Role or User"));
return Future.error(ArgumentError("The `id` property must be either Role or User"));
}
final permSet = perms._build();

View file

@ -61,7 +61,7 @@ abstract class GuildTextChannel implements Channel, CachelessGuildChannel, IText
/// ```
Future<Webhook> createWebhook(String name, {File? avatarFile, String? auditReason}) async {
if (name.isEmpty || name.length > 80) {
return Future.error("Webhook name cannot be shorter than 1 character and longer than 80 characters");
return Future.error(ArgumentError("Webhook name cannot be shorter than 1 character and longer than 80 characters"));
}
final body = <String, dynamic>{"name": name};

View file

@ -303,11 +303,11 @@ class Guild extends SnowflakeEntity implements Disposable {
/// ```
Future<GuildEmoji> createEmoji(String name, {List<Role>? roles, File? image, List<int>? imageBytes}) async {
if (image != null && await image.length() > 256000) {
return Future.error("Emojis and animated emojis have a maximum file size of 256kb.");
return Future.error(ArgumentError("Emojis and animated emojis have a maximum file size of 256kb."));
}
if (image == null && imageBytes == null) {
return Future.error("Both imageData and file fields cannot be null");
return Future.error(ArgumentError("Both imageData and file fields cannot be null"));
}
final body = <String, dynamic>{
@ -408,7 +408,7 @@ class Guild extends SnowflakeEntity implements Disposable {
final channel = this.channels.first as CacheGuildChannel?;
if (channel == null) {
return Future.error("Cannot get any channel to create invite to");
return Future.error(ArgumentError("Cannot get any channel to create invite to"));
}
return channel.createInvite(
@ -535,11 +535,11 @@ class Guild extends SnowflakeEntity implements Disposable {
String? auditReason}) async {
// Checks to avoid API panic
if (type == ChannelType.dm || type == ChannelType.groupDm) {
return Future.error("Cannot create DM channel.");
return Future.error(ArgumentError("Cannot create DM channel."));
}
if (type == ChannelType.category && parent != null) {
return Future.error("Cannot create Category Channel which have parent channel.");
return Future.error(ArgumentError("Cannot create Category Channel which have parent channel."));
}
// Construct body
@ -580,7 +580,7 @@ class Guild extends SnowflakeEntity implements Disposable {
} else if (absolute != null) {
newPosition = absolute;
} else {
return Future.error("Cannot move channel by zero places");
return Future.error(ArgumentError("Cannot move channel by zero places"));
}
await client._http._execute(BasicRequest._new("/guilds/${this.id}/channels",

View file

@ -80,7 +80,7 @@ class GuildEmoji extends IGuildEmoji implements SnowflakeEntity, GuildEntity {
/// Allows to edit emoji
Future<GuildEmoji> edit({String? name, List<Snowflake>? roles}) async {
if (name == null && roles == null) {
return Future.error("Both name and roles fields cannot be null");
return Future.error(ArgumentError("Both name and roles fields cannot be null"));
}
final body = <String, dynamic>{

View file

@ -230,7 +230,7 @@ abstract class Message extends SnowflakeEntity implements Disposable {
/// Edits the message.
Future<Message> edit({dynamic content, EmbedBuilder? embed, AllowedMentions? allowedMentions}) async {
if (this.author.id != client.self.id) {
return Future.error("Cannot edit someones message");
return Future.error(ArgumentError("Cannot edit someones message"));
}
final body = <String, dynamic>{