Handling DB Constraint violation error for required field

Certified Senior Developer

 I am using a a!writeToDataStoreEntity function inside a webAPI to write data to a table. If there is any constraint violation, I am not able to handle it properly, instead the calling service receives a 500 Internal Server Error. Is there a way to give a json response back in this case when there is a DB constraint violation error. The error I see in webAPI  is as below:

com.appiancorp.core.expr.portable.Value cannot be cast to com.appiancorp.core.data.Variant

  Discussion posts and replies are publicly visible

Parents
  • Hello Simik,

    Well I have some comments here, depending on the type of constraint is the solution and the use case.

    1) if the constraint failing is one I’d that doesn’t exist on the dB and the web api is getting it then the premise should always be that whoever is calling with the same data. It can be either with some process synchronizing some table between the systems. Architecturally this is known as MDM( master data management).

    2) if you are not able to ensure the data is synchronized then you can either remove the constraint or create a second table”staging” and Run something that tells you if the received value was ok, or not.

    3) If the constraint is something like uniqueness or not null I would suggest to check it or set “default” values.

    Please provide more details or example of the rules and maybe we can help you better

    Hope this helps
    Jose
Reply
  • Hello Simik,

    Well I have some comments here, depending on the type of constraint is the solution and the use case.

    1) if the constraint failing is one I’d that doesn’t exist on the dB and the web api is getting it then the premise should always be that whoever is calling with the same data. It can be either with some process synchronizing some table between the systems. Architecturally this is known as MDM( master data management).

    2) if you are not able to ensure the data is synchronized then you can either remove the constraint or create a second table”staging” and Run something that tells you if the received value was ok, or not.

    3) If the constraint is something like uniqueness or not null I would suggest to check it or set “default” values.

    Please provide more details or example of the rules and maybe we can help you better

    Hope this helps
    Jose
Children