From 4efc11e17150c9a8d352f337e801e533e5828f2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrej=20Rama=C5=A1euski?= <andrej@x2.cz> Date: Thu, 17 Dec 2020 01:12:17 +0100 Subject: [PATCH] Pridane trasovaci d error helpery --- lib/CF/Helpers/Core.pm | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/lib/CF/Helpers/Core.pm b/lib/CF/Helpers/Core.pm index 9a7ac8b..5712118 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 = {}; -- GitLab