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 static DigitalData.Modules.Interfaces.PropertyValues;
|
||||||
using System.Data.SqlClient;
|
using System.Data.SqlClient;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using FirebirdSql.Data.FirebirdClient;
|
|
||||||
|
|
||||||
namespace ZUGFeRDRESTService.Controllers
|
namespace ZUGFeRDRESTService.Controllers
|
||||||
{
|
{
|
||||||
@ -154,8 +153,6 @@ namespace ZUGFeRDRESTService.Controllers
|
|||||||
|
|
||||||
oZugferdResult = _zugferd.ExtractZUGFeRDFileWithGDPicture(oStream);
|
oZugferdResult = _zugferd.ExtractZUGFeRDFileWithGDPicture(oStream);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
_logger.Info("Detected Specification was: [{0}]", oZugferdResult.Specification);
|
_logger.Info("Detected Specification was: [{0}]", oZugferdResult.Specification);
|
||||||
|
|
||||||
var oFilteredPropertyMap = _zugferd.FilterPropertyMap(_propertyMap, oZugferdResult.Specification);
|
var oFilteredPropertyMap = _zugferd.FilterPropertyMap(_propertyMap, oZugferdResult.Specification);
|
||||||
@ -190,13 +187,6 @@ namespace ZUGFeRDRESTService.Controllers
|
|||||||
throw new ZUGFeRDExecption(ErrorType.MissingProperties, "Missing Properties");
|
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);
|
Tuple<bool, string> oValidateResult = ValidateBuyerOrderReference(oPropertyResult.ValidProperties);
|
||||||
|
|
||||||
if (oValidateResult.Item1 == false)
|
if (oValidateResult.Item1 == false)
|
||||||
@ -244,7 +234,6 @@ namespace ZUGFeRDRESTService.Controllers
|
|||||||
ErrorType.MissingProperties => "Die hochgeladene Datei ist keine gültige ZUGFeRD-Rechnung, es fehlen einige Metadaten.",
|
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.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.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.",
|
_ => "Die hochgeladene Datei kann nicht validiert werden.",
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -253,10 +242,6 @@ namespace ZUGFeRDRESTService.Controllers
|
|||||||
{
|
{
|
||||||
// Errors contains the list of missing fields
|
// Errors contains the list of missing fields
|
||||||
ErrorType.MissingProperties => oPropertyResult.MissingProperties,
|
ErrorType.MissingProperties => oPropertyResult.MissingProperties,
|
||||||
ErrorType.ValidationFailed => oZugferdResult.ValidationErrors.Select(e =>
|
|
||||||
{
|
|
||||||
return $"Element '{e.ElementName}' mit Wert '{e.ElementValue}': {e.ErrorMessage}";
|
|
||||||
}).ToList(),
|
|
||||||
_ => new List<string>()
|
_ => new List<string>()
|
||||||
};
|
};
|
||||||
_logger.Info($"Responding with message: [{oMessage}]");
|
_logger.Info($"Responding with message: [{oMessage}]");
|
||||||
@ -268,6 +253,21 @@ namespace ZUGFeRDRESTService.Controllers
|
|||||||
errors = oErrors
|
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)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_logger.Error(ex);
|
_logger.Error(ex);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user