Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEATURE: Custom error http codes can be defined in ValidationRule #2420

Merged
merged 9 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProjectType>Local</ProjectType>
Expand Down Expand Up @@ -210,7 +210,7 @@
<Version>2.0.15</Version>
</PackageReference>
<PackageReference Include="Origam.Service.Core">
<Version>2.2.2</Version>
<Version>2.3.1</Version>
</PackageReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets">
Expand Down
2 changes: 1 addition & 1 deletion backend/Origam.BI.Excel/Origam.BI.Excel.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NPOI" Version="2.6.2" />
<PackageReference Include="Origam.Service.Core" Version="2.2.2" />
<PackageReference Include="Origam.Service.Core" Version="2.3.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Origam.Workbench.Services\Origam.Workbench.Services.csproj" />
Expand Down
2 changes: 1 addition & 1 deletion backend/Origam.BI.FastReport/Origam.BI.FastReport.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@

<ItemGroup>
<PackageReference Include="FastReport.OpenSource.Export.PdfSimple" Version="2024.1.3" />
<PackageReference Include="Origam.Service.Core" Version="2.2.2" />
<PackageReference Include="Origam.Service.Core" Version="2.3.1" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions backend/Origam.BI.PrintIt/Origam.BI.PrintIt.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProjectType>Local</ProjectType>
Expand Down Expand Up @@ -140,7 +140,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Origam.Service.Core">
<Version>2.2.2</Version>
<Version>2.3.1</Version>
</PackageReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets">
Expand Down
4 changes: 2 additions & 2 deletions backend/Origam.BI/Origam.BI.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProjectType>Local</ProjectType>
Expand Down Expand Up @@ -145,7 +145,7 @@
<Version>2.0.15</Version>
</PackageReference>
<PackageReference Include="Origam.Service.Core">
<Version>2.2.2</Version>
<Version>2.3.1</Version>
</PackageReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets">
Expand Down
2 changes: 1 addition & 1 deletion backend/Origam.Common/Origam.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="6.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Origam.Service.Core" Version="2.2.2" />
<PackageReference Include="Origam.Service.Core" Version="2.3.1" />
<PackageReference Include="System.Drawing.Common" Version="5.0.3" />
<PackageReference Include="System.IO.FileSystem" Version="4.3.0" />
<PackageReference Include="System.Net.NameResolution" Version="4.3.0" />
Expand Down
4 changes: 2 additions & 2 deletions backend/Origam.Gui.Win/Origam.Gui.Win.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProjectType>Local</ProjectType>
Expand Down Expand Up @@ -679,7 +679,7 @@
<Version>3.1.0</Version>
</PackageReference>
<PackageReference Include="Origam.Service.Core">
<Version>2.2.2</Version>
<Version>2.3.1</Version>
</PackageReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets">
Expand Down
2 changes: 1 addition & 1 deletion backend/Origam.Server/Origam.Server.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="6.0.9" />
<PackageReference Include="Microsoft.Extensions.Logging.Log4Net.AspNetCore" Version="7.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="6.0.10" />
<PackageReference Include="Origam.Service.Core" Version="2.2.2" />
<PackageReference Include="Origam.Service.Core" Version="2.3.1" />
<PackageReference Include="SoapCore" Version="1.1.0.41" />
<PackageReference Include="System.Data.DataSetExtensions" Version="4.5.0" />
<PackageReference Include="UAParser" Version="3.1.47" />
Expand Down
17 changes: 16 additions & 1 deletion backend/Origam.Server/Pages/UserApiProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,28 @@ IParameterService parameterService
message = JsonConvert.SerializeObject(ex);
}
context.Response.Clear();
context.Response.StatusCode = 400;
context.Response.StatusCode = GetStausCode(ex);
context.Response.ContentType = "application/json";
context.Response.Write(message);
context.Response.End();
}
}

private int GetStausCode(Exception ex)
{
if (ex is RuleException ruleException)
{
var dataList = ruleException.RuleResult
.OfType<RuleExceptionData>()
.ToList();
if (dataList.Count == 1)
{
return dataList[0].HttpStatusCode;
}
}
return 400;
}

protected virtual void Handle404(IHttpContextWrapper context)
{
// nothing found, let others handle it
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProjectType>Local</ProjectType>
Expand Down Expand Up @@ -159,7 +159,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Origam.Service.Core">
<Version>2.2.2</Version>
<Version>2.3.1</Version>
</PackageReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets">
Expand Down
2 changes: 1 addition & 1 deletion backend/OrigamArchitect/OrigamArchitect.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@
<Version>2.6.2</Version>
</PackageReference>
<PackageReference Include="Origam.Service.Core">
<Version>2.2.2</Version>
<Version>2.3.1</Version>
</PackageReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@
x:id="5643627e-99f8-4df4-bfd6-d31db81cad4a"
asi:name="RuleExceptionData"
ade:readOnly="false">
<df:DataEntityColumn
asi:abstract="false"
adec:allowNulls="true"
adec:autoIncrement="false"
adec:dataType="Integer"
adec:excludeFromAllFields="false"
x:id="4020bc56-a75e-4da6-87b1-d62af56a25e9"
adec:isPrimaryKey="false"
asi:name="HttpStatusCode"
adec:onCopyAction="Copy"
adec:xmlMappingType="Attribute" />
<df:DataEntityColumn
asi:abstract="false"
adec:allowNulls="false"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<x:file
xmlns:x="http://schemas.origam.com/model-persistence/1.0.0"
xmlns:ar="http://schemas.origam.com/Origam.Schema.RuleModel.AbstractRule/6.0.0"
xmlns:ar1="http://schemas.origam.com/Origam.Schema.RuleModel.AbstractRule/6.0.0"
xmlns:asi="http://schemas.origam.com/Origam.Schema.AbstractSchemaItem/6.0.0"
xmlns:er="http://schemas.origam.com/Origam.Schema.RuleModel.EndRule/6.0.0"
xmlns:er1="http://schemas.origam.com/Origam.Schema.RuleModel.EndRule/6.0.0"
xmlns:xr="http://schemas.origam.com/Origam.Schema.RuleModel.XslRule/6.0.0">
<er:Rule
<er1:Rule
asi:abstract="false"
ar:dataType="Boolean"
ar1:dataType="Boolean"
x:id="e1c65fcd-118d-4eb3-9c2f-aa27fec132ba"
asi:name="ER_ExceptionTemplate"
xr:xsl="-***-ExternalFile:ER_ExceptionTemplate.origam___xsl___e1c65fcd-118d-4eb3-9c2f-aa27fec132ba.xslt" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<xsl:param name="EntityName"/>
<xsl:param name="Message"/>
<xsl:param name="Severity"/>
<xsl:param name="HttpStatusCode" select="400"/>

<RuleExceptionData>
<FieldName>
Expand All @@ -19,6 +20,9 @@
<Severity>
<xsl:value-of select="$Severity"/>
</Severity>
<HttpStatusCode>
<xsl:value-of select="$HttpStatusCode"/>
</HttpStatusCode>
</RuleExceptionData>
</xsl:template>
</xsl:stylesheet>
3 changes: 3 additions & 0 deletions model-tests/ApiCallExamples/publicApiTestExamples.http
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
GET https://localhost:{{port}}/api/public/Attachment/E65251F1-FD5B-4307-B0A7-4C9F5594A1AF


###
// fails and sends custom http return core
GET https://localhost:{{port}}/api/public/failingWorkflow
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@
x:id="5643627e-99f8-4df4-bfd6-d31db81cad4a"
asi:name="RuleExceptionData"
ade:readOnly="false">
<df:DataEntityColumn
asi:abstract="false"
adec:allowNulls="true"
adec:autoIncrement="false"
adec:dataType="Integer"
adec:excludeFromAllFields="false"
x:id="4020bc56-a75e-4da6-87b1-d62af56a25e9"
adec:isPrimaryKey="false"
asi:name="HttpStatusCode"
adec:onCopyAction="Copy"
adec:xmlMappingType="Attribute" />
<df:DataEntityColumn
asi:abstract="false"
adec:allowNulls="false"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<x:file
xmlns:x="http://schemas.origam.com/model-persistence/1.0.0"
xmlns:ar="http://schemas.origam.com/Origam.Schema.RuleModel.AbstractRule/6.0.0"
xmlns:ar1="http://schemas.origam.com/Origam.Schema.RuleModel.AbstractRule/6.0.0"
xmlns:asi="http://schemas.origam.com/Origam.Schema.AbstractSchemaItem/6.0.0"
xmlns:er="http://schemas.origam.com/Origam.Schema.RuleModel.EndRule/6.0.0"
xmlns:er1="http://schemas.origam.com/Origam.Schema.RuleModel.EndRule/6.0.0"
xmlns:xr="http://schemas.origam.com/Origam.Schema.RuleModel.XslRule/6.0.0">
<er:Rule
<er1:Rule
asi:abstract="false"
ar:dataType="Boolean"
ar1:dataType="Boolean"
x:id="e1c65fcd-118d-4eb3-9c2f-aa27fec132ba"
asi:name="ER_ExceptionTemplate"
xr:xsl="-***-ExternalFile:ER_ExceptionTemplate.origam___xsl___e1c65fcd-118d-4eb3-9c2f-aa27fec132ba.xslt" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<xsl:param name="EntityName"/>
<xsl:param name="Message"/>
<xsl:param name="Severity"/>
<xsl:param name="HttpStatusCode" select="400"/>

<RuleExceptionData>
<FieldName>
Expand All @@ -19,6 +20,9 @@
<Severity>
<xsl:value-of select="$Severity"/>
</Severity>
<HttpStatusCode>
<xsl:value-of select="$HttpStatusCode"/>
</HttpStatusCode>
</RuleExceptionData>
</xsl:template>
</xsl:stylesheet>
18 changes: 18 additions & 0 deletions model-tests/model/Widgets/Page/FailingWorkflow.origam
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<x:file
xmlns:x="http://schemas.origam.com/model-persistence/1.0.0"
xmlns:ap="http://schemas.origam.com/Origam.Schema.GuiModel.AbstractPage/6.0.0"
xmlns:asi="http://schemas.origam.com/Origam.Schema.AbstractSchemaItem/6.0.0"
xmlns:wp="http://schemas.origam.com/Origam.Schema.WorkflowModel.WorkflowPage/6.0.0">
<wp:Page
asi:abstract="false"
ap:allowDelete="false"
ap:allowPut="false"
wp:disableConstraintForInputValidation="false"
x:id="9bd0c179-64b8-4387-b98d-24d2eb3b3e8e"
ap:mimeType="application/json"
asi:name="FailingWorkflow"
ap:roles="*"
ap:url="api/public/failingWorkflow"
wp:workflow="Widgets/Workflow/Widgets/FailingWorkQueueTest.origam#FailingWorkQueueTest/ddb1cedf-c05a-472f-bb5d-f5d070e627ed" />
</x:file>
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<xsl:with-param name="EntityName"><xsl:value-of select="'WorkQueueEntry'"/></xsl:with-param>
<xsl:with-param name="Message"><xsl:value-of select="AS:GetString('TestError')"/></xsl:with-param>
<xsl:with-param name="Severity"><xsl:value-of select="'High'"/></xsl:with-param>
<xsl:with-param name="HttpStatusCode"><xsl:value-of select="402"/></xsl:with-param>
</xsl:call-template>
</xsl:if>
</RuleExceptionDataCollection>
Expand Down
3 changes: 2 additions & 1 deletion test/tests_e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"@babel/helper-get-function-arity": "^7.16.7",
"jest": "^27.3.1",
"jest-trx-results-processor": "^3.0.2",
"msnodesqlv8": "^2.2.0",
"msnodesqlv8": "^4.1.2",
"mssql": "^7.2.1",
"puppeteer": "^10.1.0"
},
Expand Down