Skip to content

Instantly share code, notes, and snippets.

@PhantomKnight287
Created September 26, 2024 04:37
Show Gist options
  • Select an option

  • Save PhantomKnight287/71d9d2c4f14d92cef79ea71d87e341d5 to your computer and use it in GitHub Desktop.

Select an option

Save PhantomKnight287/71d9d2c4f14d92cef79ea71d87e341d5 to your computer and use it in GitHub Desktop.
Helper to get error message from a class validator error
String getErrorMessage(dynamic error, [String? message]) {
if (error is String) {
return error;
} else if (error is Map) {
if (error['message'] is List) {
return error['message'][0];
} else {
return error['message'];
}
} else {
return message ?? 'Something went wrong';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment