hilla
hilla copied to clipboard
[autoform] Handle optimistic locking exceptions
If the entity the form is editing has a @Version
field and submit/save fails because of using an old entity, there should be an error message stating the issue ("somebody else edited the data") and what the user should do to get a fresh copy to start from
Currently (2.4.0.alpha1), we get a 500 response with this message like: "Endpoint 'PersonService' method 'save' execution failure", so there's no way to detect an optimistic locking exception on the client.
As a quick fix for now, would it be good enough to document that people should throw an EndpointException
in Java with the appropriate message?
For example, in Java
@Endpoint
public class DataEndpoint {
public String save(String s) {
throw new EndpointException("Optimistic locking exception");
}
}
then in TS
try {
await DataEndpoint.save("something");
} catch (error) {
if (error instanceof EndpointError && (error as EndpointError).message.startsWith("Optimistic locking") ) {
// do something (e.g., re-fetch data from server)
}
}
Yes, developers could catch org.springframework.orm.ObjectOptimisticLockingFailureException
.