diff --git a/lib/CF/Helpers/Core.pm b/lib/CF/Helpers/Core.pm index 9a7ac8bdb574adfb639a1086abd267126c07fd42..5712118b7699f91f56f4feda79a0087e37aea517 100644 --- a/lib/CF/Helpers/Core.pm +++ b/lib/CF/Helpers/Core.pm @@ -6,10 +6,36 @@ no warnings qw{ experimental::signatures } ; sub register ($class, $self, $conf) { - $self->helper( spec_filter => sub { - my $c = shift; - my $data = shift; - my $class = shift; + $self->helper(error => sub ($c, $status, $errors=[]) { + + if ( scalar @_ == 2 ) { + $errors = [{ code => shift, message => shift }]; + } + elsif ( ref $_[0] eq 'ARRAY' ) { + $errors = shift; + } + elsif ( ref $_[0] eq 'HASH' ) { + $errors = [ shift ]; + } + else { + $errors = [{ message => shift, code => undef }]; + } + + $c->stash( + status => $status, + openapi => { errors => $errors } + ); + + return undef; + }); + + $self->helper( trace => sub( $c, $data='' ) { + $data = Dump $data if ref $data; + $c->app->log->debug($data); + + }); + + $self->helper( spec_filter => sub ($c, $data, $class) { if (my $def =$c->openapi->spec("/components/schemas/$class")) { my $filtered = {};