Skip to content

fix(orchestrator): refactor 500 response to use ErrorResponse object #1290

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

Merged
merged 2 commits into from
Feb 29, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 48 additions & 16 deletions plugins/orchestrator-backend/src/service/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,9 @@ function setupInternalRoutes(
await V1.getWorkflowsOverview(services.sonataFlowService)
.then(result => res.status(200).json(result))
.catch(error => {
res.status(500).send(error.message || 'Internal Server Error');
res
.status(500)
.json({ message: error.message || 'internal server error' });
});
});

Expand All @@ -165,7 +167,9 @@ function setupInternalRoutes(
await V2.getWorkflowsOverview(services.sonataFlowService)
.then(result => res.json(result))
.catch(error => {
res.status(500).send(error.message || 'internal Server Error');
res
.status(500)
.json({ message: error.message || 'internal server error' });
next();
});
},
Expand All @@ -175,7 +179,9 @@ function setupInternalRoutes(
await V1.getWorkflows(services.sonataFlowService, services.dataIndexService)
.then(result => res.status(200).json(result))
.catch(error => {
res.status(500).send(error.message || 'internal Server Error');
res
.status(500)
.json({ message: error.message || 'internal server error' });
});
});

Expand All @@ -184,7 +190,9 @@ function setupInternalRoutes(
await V2.getWorkflows(services.sonataFlowService, services.dataIndexService)
.then(result => res.json(result))
.catch(error => {
res.status(500).send(error.message || 'internal Server Error');
res
.status(500)
.json({ message: error.message || 'internal server error' });
next();
});
});
Expand All @@ -196,7 +204,9 @@ function setupInternalRoutes(
await V1.getWorkflowById(services.sonataFlowService, workflowId)
.then(result => res.status(200).json(result))
.catch(error => {
res.status(500).send(error.message || 'Internal Server Error');
res
.status(500)
.json({ message: error.message || 'internal server error' });
});
});

Expand All @@ -207,7 +217,9 @@ function setupInternalRoutes(
await V2.getWorkflowById(services.sonataFlowService, workflowId)
.then(result => res.json(result))
.catch(error => {
res.status(500).send(error.message || 'Internal Server Error');
res
.status(500)
.json({ message: error.message || 'internal server error' });
next();
});
});
Expand All @@ -220,7 +232,9 @@ function setupInternalRoutes(
await V1.abortWorkflow(services.dataIndexService, workflowId)
.then(result => res.status(200).json(result.data))
.catch(error => {
res.status(500).send(error.message || 'Internal Server Error');
res
.status(500)
.json({ message: error.message || 'internal server error' });
});
});

Expand All @@ -230,7 +244,9 @@ function setupInternalRoutes(
await V2.abortWorkflow(services.dataIndexService, workflowId)
.then(result => res.json(result))
.catch(error => {
res.status(500).send(error.message || 'Internal Server Error');
res
.status(500)
.json({ message: error.message || 'internal server error' });
next();
});
});
Expand All @@ -251,7 +267,9 @@ function setupInternalRoutes(
)
.then((result: any) => res.status(200).json(result))
.catch((error: { message: any }) => {
res.status(500).send(error.message || 'Internal Server Error');
res
.status(500)
.json({ message: error.message || 'internal server error' });
});
});

Expand All @@ -275,7 +293,9 @@ function setupInternalRoutes(
)
.then(result => res.status(200).json(result))
.catch((error: { message: string }) => {
res.status(500).send(error.message || 'Internal Server Error');
res
.status(500)
.json({ message: error.message || 'internal server error' });
});
},
);
Expand All @@ -300,7 +320,9 @@ function setupInternalRoutes(
)
.then(result => res.status(200).json(result))
.catch((error: { message: string }) => {
res.status(500).send(error.message || 'Internal Server Error');
res
.status(500)
.json({ message: error.message || 'internal server error' });
});
},
);
Expand Down Expand Up @@ -331,7 +353,9 @@ function setupInternalRoutes(
await V1.getInstances(services.dataIndexService)
.then(result => res.status(200).json(result))
.catch(error => {
res.status(500).send(error.message || 'internal Server Error');
res
.status(500)
.json({ message: error.message || 'internal server error' });
});
});

Expand Down Expand Up @@ -362,7 +386,9 @@ function setupInternalRoutes(
)
.then(result => res.status(200).json(result))
.catch(error => {
res.status(500).send(error.message || 'Internal Server Error');
res
.status(500)
.json({ message: error.message || 'internal server error' });
});
});

Expand All @@ -382,7 +408,9 @@ function setupInternalRoutes(
)
.then(result => res.status(200).json(result))
.catch(error => {
res.status(500).send(error.message || 'Internal Server Error');
res
.status(500)
.json({ message: error.message || 'internal server error' });
next();
});
},
Expand Down Expand Up @@ -515,7 +543,9 @@ function setupInternalRoutes(
await V2.getWorkflowResults(services.dataIndexService, instanceId)
.then(result => res.status(200).json(result))
.catch((error: { message: string }) => {
res.status(500).send(error.message || 'Internal Server Error');
res
.status(500)
.json({ message: error.message || 'internal server error' });
});
},
);
Expand All @@ -527,7 +557,9 @@ function setupInternalRoutes(
await V2.getWorkflowStatuses()
.then(result => res.status(200).json(result))
.catch((error: { message: string }) => {
res.status(500).send(error.message || 'Internal Server Error');
res
.status(500)
.json({ message: error.message || 'internal server error' });
});
},
);
Expand Down
3 changes: 2 additions & 1 deletion plugins/orchestrator-common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"clean": "backstage-cli package clean",
"prepack": "backstage-cli package prepack",
"postpack": "backstage-cli package postpack",
"openapi": "./scripts/openapi.sh"
"openapi": "./scripts/openapi.sh",
"openapi:prettier:fix": "prettier --ignore-unknown --write ./src/auto-generated"
},
"dependencies": {
"@backstage/types": "^1.1.1",
Expand Down
3 changes: 2 additions & 1 deletion plugins/orchestrator-common/scripts/openapi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ cat ./src/openapi/openapi.json >> ${FILE}
echo '`' >> ${FILE}
echo "export const openApiDocument = JSON.parse(OPENAPI);" >> ${FILE}

rm ./src/openapi/openapi.json
rm ./src/openapi/openapi.json
yarn openapi:prettier:fix
58 changes: 38 additions & 20 deletions plugins/orchestrator-common/src/auto-generated/api/definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ const OPENAPI = `
"500": {
"description": "Error fetching workflow overviews",
"content": {
"text/plain": {
"application/json": {
"schema": {
"type": "string"
"$ref": "#/components/schemas/ErrorResponse"
}
}
}
Expand Down Expand Up @@ -74,9 +74,9 @@ const OPENAPI = `
"500": {
"description": "Error fetching workflow overview",
"content": {
"text/plain": {
"application/json": {
"schema": {
"type": "string"
"$ref": "#/components/schemas/ErrorResponse"
}
}
}
Expand All @@ -102,9 +102,9 @@ const OPENAPI = `
"500": {
"description": "Error fetching workflow list",
"content": {
"text/plain": {
"application/json": {
"schema": {
"type": "string"
"$ref": "#/components/schemas/ErrorResponse"
}
}
}
Expand Down Expand Up @@ -141,9 +141,9 @@ const OPENAPI = `
"500": {
"description": "Error workflow by id",
"content": {
"text/plain": {
"application/json": {
"schema": {
"type": "string"
"$ref": "#/components/schemas/ErrorResponse"
}
}
}
Expand All @@ -170,9 +170,9 @@ const OPENAPI = `
"500": {
"description": "Error fetching instances",
"content": {
"text/plain": {
"application/json": {
"schema": {
"type": "string"
"$ref": "#/components/schemas/ErrorResponse"
}
}
}
Expand Down Expand Up @@ -209,9 +209,9 @@ const OPENAPI = `
"500": {
"description": "Error fetching instance",
"content": {
"text/plain": {
"application/json": {
"schema": {
"type": "string"
"$ref": "#/components/schemas/ErrorResponse"
}
}
}
Expand Down Expand Up @@ -248,9 +248,9 @@ const OPENAPI = `
"500": {
"description": "Error getting workflow results",
"content": {
"text/plain": {
"application/json": {
"schema": {
"type": "string"
"$ref": "#/components/schemas/ErrorResponse"
}
}
}
Expand Down Expand Up @@ -280,9 +280,9 @@ const OPENAPI = `
"500": {
"description": "Error fetching workflow statuses",
"content": {
"text/plain": {
"application/json": {
"schema": {
"type": "string"
"$ref": "#/components/schemas/ErrorResponse"
}
}
}
Expand Down Expand Up @@ -329,9 +329,9 @@ const OPENAPI = `
"500": {
"description": "Internal Server Error",
"content": {
"text/plain": {
"application/json": {
"schema": {
"type": "string"
"$ref": "#/components/schemas/ErrorResponse"
}
}
}
Expand Down Expand Up @@ -369,9 +369,9 @@ const OPENAPI = `
"500": {
"description": "Error aborting workflow",
"content": {
"text/plain": {
"application/json": {
"schema": {
"type": "string"
"$ref": "#/components/schemas/ErrorResponse"
}
}
}
Expand All @@ -382,6 +382,24 @@ const OPENAPI = `
},
"components": {
"schemas": {
"ErrorResponse": {
"description": "The ErrorResponse object represents a common structure for handling errors in API responses. It includes essential information about the error, such as the error message and additional optional details.",
"type": "object",
"properties": {
"message": {
"description": "A string providing a concise and human-readable description of the encountered error. This field is required in the ErrorResponse object.",
"type": "string",
"default": "internal server error"
},
"additionalInfo": {
"description": "An optional field that can contain additional information or context about the error. It provides flexibility for including extra details based on specific error scenarios.",
"type": "string"
}
},
"required": [
"message"
]
},
"WorkflowOverviewListResultDTO": {
"type": "object",
"properties": {
Expand Down
Loading