handle ValidationException
This commit is contained in:
parent
0f314e1c85
commit
fdaf94db2e
@ -10,7 +10,6 @@ using static DigitalData.Modules.Interfaces.ZUGFeRDInterface;
|
||||
using static DigitalData.Modules.Interfaces.PropertyValues;
|
||||
using System.Data.SqlClient;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using FirebirdSql.Data.FirebirdClient;
|
||||
|
||||
namespace ZUGFeRDRESTService.Controllers
|
||||
{
|
||||
@ -152,9 +151,7 @@ namespace ZUGFeRDRESTService.Controllers
|
||||
|
||||
_logger.Info("Extracting ZUGFeRD Data from file [{0}]", file.FileName);
|
||||
|
||||
oZugferdResult = _zugferd.ExtractZUGFeRDFileWithGDPicture(oStream);
|
||||
|
||||
|
||||
oZugferdResult = _zugferd.ExtractZUGFeRDFileWithGDPicture(oStream);
|
||||
|
||||
_logger.Info("Detected Specification was: [{0}]", oZugferdResult.Specification);
|
||||
|
||||
@ -188,14 +185,7 @@ namespace ZUGFeRDRESTService.Controllers
|
||||
if (oPropertyResult.MissingProperties.Count > 0)
|
||||
{
|
||||
throw new ZUGFeRDExecption(ErrorType.MissingProperties, "Missing Properties");
|
||||
}
|
||||
|
||||
oZugferdResult = _zugferd.ValidateZUGFeRDDocument(oZugferdResult);
|
||||
|
||||
if (oZugferdResult.ValidationErrors.Any())
|
||||
{
|
||||
throw new ZUGFeRDExecption(ErrorType.ValidationFailed, "Validation Failed");
|
||||
}
|
||||
}
|
||||
|
||||
Tuple<bool, string> oValidateResult = ValidateBuyerOrderReference(oPropertyResult.ValidProperties);
|
||||
|
||||
@ -244,7 +234,6 @@ namespace ZUGFeRDRESTService.Controllers
|
||||
ErrorType.MissingProperties => "Die hochgeladene Datei ist keine gültige ZUGFeRD-Rechnung, es fehlen einige Metadaten.",
|
||||
ErrorType.FileTooBig => string.Format("Die hochgeladene Datei überschreitet die zulässige Dateigröße [{0}].", _MaxFileSizeInMegabytes),
|
||||
ErrorType.UnsupportedFormat => "Die hochgeladene Datei enthält ein falsches oder nicht unterstütztes ZUGFeRD Format.",
|
||||
ErrorType.ValidationFailed => "Die hochgeladene Datei enthält ungültige Werte.",
|
||||
_ => "Die hochgeladene Datei kann nicht validiert werden.",
|
||||
};
|
||||
|
||||
@ -253,10 +242,6 @@ namespace ZUGFeRDRESTService.Controllers
|
||||
{
|
||||
// Errors contains the list of missing fields
|
||||
ErrorType.MissingProperties => oPropertyResult.MissingProperties,
|
||||
ErrorType.ValidationFailed => oZugferdResult.ValidationErrors.Select(e =>
|
||||
{
|
||||
return $"Element '{e.ElementName}' mit Wert '{e.ElementValue}': {e.ErrorMessage}";
|
||||
}).ToList(),
|
||||
_ => new List<string>()
|
||||
};
|
||||
_logger.Info($"Responding with message: [{oMessage}]");
|
||||
@ -268,6 +253,21 @@ namespace ZUGFeRDRESTService.Controllers
|
||||
errors = oErrors
|
||||
};
|
||||
}
|
||||
catch (ValidationException ex)
|
||||
{
|
||||
string oMessage = "Die hochgeladene Datei enthält ungültige Werte.";
|
||||
List<string> oErrors = ex.ValidationErrors.Select(e =>
|
||||
{
|
||||
return $"Element '{e.ElementName}' mit Wert '{e.ElementValue}': {e.ErrorMessage}";
|
||||
}).ToList();
|
||||
|
||||
return new ValidationResponse()
|
||||
{
|
||||
status = RESPONSE_ERROR,
|
||||
message = oMessage,
|
||||
errors = oErrors
|
||||
};
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.Error(ex);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user