Validate: Human-readable error messages

This commit is contained in:
Yorhel 2025-03-06 10:16:12 +01:00
parent e4b6b77e1b
commit e5755ddd80
3 changed files with 79 additions and 56 deletions

4
FU.pm
View file

@ -640,8 +640,8 @@ sub _getfield($data, @a) {
require FU::Validate;
my $schema = FU::Validate->compile(@a > 1 ? { keys => {@a} } : $a[0]);
my $res = eval { $schema->validate($data) };
fu->error(400, "Input validation failed") if $@; # TODO: More detailed error message
return @a == 2 ? $res->data->{$a[0]} : $res->data;
fu->error(400, "Input validation failed: $@") if $@;
return @a == 2 ? $res->{$a[0]} : $res;
}
sub query {