Trying to improve PHP validation error message
This commit is contained in:
parent
216b23fab5
commit
ba85357dba
|
@ -60,11 +60,11 @@ class %class% %parent_class%
|
|||
|
||||
function import(&\$message, \$assoc = false, \$root = true)
|
||||
{
|
||||
\$IDX = 0;
|
||||
\$IDX = -1;
|
||||
try
|
||||
{
|
||||
if(!is_array(\$message))
|
||||
throw new Exception("Bad message: \$message");
|
||||
throw new Exception("Bad data: \$message");
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -72,8 +72,13 @@ class %class% %parent_class%
|
|||
}
|
||||
catch(Exception \$e)
|
||||
{
|
||||
if(\$IDX > -1)
|
||||
{
|
||||
\$FIELDS = self::CLASS_FIELDS();
|
||||
throw new Exception("Error while filling field '{\$FIELDS[\$IDX]}': " . \$e->getMessage());
|
||||
throw new Exception(\$e->getMessage() . " < {\$FIELDS[\$IDX]}");
|
||||
}
|
||||
else
|
||||
throw \$e;
|
||||
}
|
||||
|
||||
if(\$root && \$assoc && sizeof(\$message) > 0)
|
||||
|
@ -81,7 +86,7 @@ class %class% %parent_class%
|
|||
}
|
||||
catch(Exception \$e)
|
||||
{
|
||||
throw new Exception("Error while filling fields of '%class%':" . \$e->getMessage());
|
||||
throw new Exception(\$e->getMessage() . " < (%class%)");
|
||||
}
|
||||
return \$IDX;
|
||||
}
|
||||
|
@ -106,7 +111,7 @@ class %class% %parent_class%
|
|||
}
|
||||
catch(Exception \$e)
|
||||
{
|
||||
throw new Exception("Error while dumping fields of '%class%'->\$__last_var: ". PHP_EOL . serialize(\$__last_val) . PHP_EOL."\t" . \$e->getMessage());
|
||||
throw new Exception("[%class%]\n->\$__last_var\n" . serialize(\$__last_val) . PHP_EOL."\t" . \$e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -255,17 +260,22 @@ class %class% %parent_class%
|
|||
try
|
||||
{
|
||||
if(!\$message || !is_array(\$message))
|
||||
throw new Exception("Bad message");
|
||||
throw new Exception("Bad data");
|
||||
|
||||
\$IDX = 0;
|
||||
\$IDX = -1;
|
||||
try
|
||||
{
|
||||
%fill_fields%
|
||||
}
|
||||
catch(Exception \$e)
|
||||
{
|
||||
if(\$IDX > -1)
|
||||
{
|
||||
\$FIELDS = self::CLASS_FIELDS();
|
||||
throw new Exception("Error while filling field '{\$FIELDS[\$IDX]}': " . \$e->getMessage());
|
||||
throw new Exception(\$e->getMessage() . " < {\$FIELDS[\$IDX]}");
|
||||
}
|
||||
else
|
||||
throw \$e;
|
||||
}
|
||||
|
||||
if(\$root && \$assoc && sizeof(\$message) > 0)
|
||||
|
@ -273,7 +283,7 @@ class %class% %parent_class%
|
|||
}
|
||||
catch(Exception \$e)
|
||||
{
|
||||
throw new Exception("Error while filling fields of '%class%':" . \$e->getMessage());
|
||||
throw new Exception(\$e->getMessage() . " < (%class%)");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -289,7 +299,7 @@ class %class% %parent_class%
|
|||
}
|
||||
catch(Exception \$e)
|
||||
{
|
||||
throw new Exception("Error while dumping fields of '%class%':" . \$e->getMessage());
|
||||
throw new Exception(\$e->getMessage() . "\n(%class%)");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue