Skip to content

Commit

Permalink
Forwarding error responses from Formio. (#1704)
Browse files Browse the repository at this point in the history
  • Loading branch information
auslin-aot authored Nov 13, 2023
1 parent 34782f8 commit 6e56e9c
Showing 1 changed file with 45 additions and 26 deletions.
71 changes: 45 additions & 26 deletions forms-flow-api/src/formsflow_api/resources/form_process_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from flask import request
from flask_restx import Namespace, Resource, fields
from formsflow_api_utils.exceptions import BusinessException
from formsflow_api_utils.services.external import FormioService
from formsflow_api_utils.utils import (
DESIGNER_GROUP,
Expand Down Expand Up @@ -495,22 +496,30 @@ class FormioFormResource(Resource):
)
def post():
"""Formio form creation method."""
data = request.get_json()
formio_service = FormioService()
form_io_token = formio_service.get_formio_access_token()
response, status = (
formio_service.create_form(data, form_io_token),
HTTPStatus.CREATED,
)
FormHistoryService.create_form_log_with_clone(
data={
**response,
"parentFormId": data.get("parentFormId"),
"newVersion": data.get("newVersion"),
"componentChanged": True,
}
)
return response, status
try:
data = request.get_json()
formio_service = FormioService()
form_io_token = formio_service.get_formio_access_token()
response, status = (
formio_service.create_form(data, form_io_token),
HTTPStatus.CREATED,
)
FormHistoryService.create_form_log_with_clone(
data={
**response,
"parentFormId": data.get("parentFormId"),
"newVersion": data.get("newVersion"),
"componentChanged": True,
}
)
return response, status
except BusinessException as err:
message = (
err.details[0]["message"]
if hasattr(err, "details") and err.details
else err.message
)
return message, err.status_code


@cors_preflight("PUT,OPTIONS")
Expand All @@ -523,16 +532,26 @@ class FormioFormUpdateResource(Resource):
@profiletime
def put(form_id: str):
"""Formio form update method."""
FormProcessMapperService.check_tenant_authorization_by_formid(form_id=form_id)
data = request.get_json()
formio_service = FormioService()
form_io_token = formio_service.get_formio_access_token()
response, status = (
formio_service.update_form(form_id, data, form_io_token),
HTTPStatus.OK,
)
FormHistoryService.create_form_log_with_clone(data=data)
return response, status
try:
FormProcessMapperService.check_tenant_authorization_by_formid(
form_id=form_id
)
data = request.get_json()
formio_service = FormioService()
form_io_token = formio_service.get_formio_access_token()
response, status = (
formio_service.update_form(form_id, data, form_io_token),
HTTPStatus.OK,
)
FormHistoryService.create_form_log_with_clone(data=data)
return response, status
except BusinessException as err:
message = (
err.details[0]["message"]
if hasattr(err, "details") and err.details
else err.message
)
return message, err.status_code


@cors_preflight("GET,OPTIONS")
Expand Down

0 comments on commit 6e56e9c

Please sign in to comment.