Commit f2fcf0f2 authored by Rustam Lotsmanenko (EPAM)'s avatar Rustam Lotsmanenko (EPAM)
Browse files

GONRG-1069 Fix datastore exception resolving

Changes:
* Unhardcode exception response message, contention transactions
can cause different messages.
parent dd0daf8f
......@@ -99,7 +99,7 @@ public class DatastoreActionRepo implements IActionRepo {
txn.put(entity);
txn.commit();
} catch (DatastoreException ex) {
if (ex.getCode() == 10 && ex.getMessage().startsWith("too much contention")) {
if (ex.getCode() == 10) {
return throwConflict();
} else
throw ex;
......@@ -129,7 +129,7 @@ public class DatastoreActionRepo implements IActionRepo {
output = true;
}
} catch (DatastoreException ex) {
if (ex.getCode() == 10 && ex.getMessage().startsWith("too much contention"))
if (ex.getCode() == 10)
throw new AppException(409, "Conflict", "Another request is trying to delete the same DDMS.");
else
throw ex;
......
......@@ -64,7 +64,7 @@ public class DatastoreDdmsRepository implements IDdmsRepository {
txn.put(entity);
txn.commit();
} catch (DatastoreException ex) {
if (ex.getCode() == 10 && ex.getMessage().startsWith("too much contention"))
if (ex.getCode() == 10)
throw new AppException(409, "Conflict", "A DDMS already exists with the same id");
else
throw ex;
......@@ -118,7 +118,7 @@ public class DatastoreDdmsRepository implements IDdmsRepository {
output = true;
}
} catch (DatastoreException ex) {
if (ex.getCode() == 10 && ex.getMessage().startsWith("too much contention"))
if (ex.getCode() == 10)
throw new AppException(409, "Conflict", "Another request is trying to delete the same DDMS.");
else
throw ex;
......
......@@ -108,6 +108,7 @@ public class DatastoreAccess implements IDatastoreAccess {
@Override
public List<Subscription> getAll() throws Exception {
Datastore ds = dataStoreTenants.get(tenantInfo.getName());
Query<Entity> q = Query
.newGqlQueryBuilder(Query.ResultType.ENTITY, "Select * from SUBSCRIPTION")
......@@ -137,7 +138,7 @@ public class DatastoreAccess implements IDatastoreAccess {
txn.put(entity);
txn.commit();
} catch (DatastoreException ex) {
if (ex.getCode() == 10 && ex.getMessage().startsWith("too much contention"))
if (ex.getCode() == 10)
throw new AppException(409, "Conflict", "A subscriber already exists with the same topic and endpoint combination");
else
throw ex;
......@@ -169,7 +170,7 @@ public class DatastoreAccess implements IDatastoreAccess {
output = true;
}
} catch (DatastoreException ex) {
if (ex.getCode() == 10 && ex.getMessage().startsWith("too much contention"))
if (ex.getCode() == 10)
throw new AppException(409, "Conflict", "Another request is trying to delete the same DDMS.");
else
throw ex;
......@@ -198,7 +199,7 @@ public class DatastoreAccess implements IDatastoreAccess {
output = true;
}
} catch (DatastoreException ex) {
if (ex.getCode() == 10 && ex.getMessage().startsWith("too much contention"))
if (ex.getCode() == 10)
throw new AppException(409, "Conflict", "Another request is trying to update the same subscription.");
else
throw ex;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment