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 { ...@@ -99,7 +99,7 @@ public class DatastoreActionRepo implements IActionRepo {
txn.put(entity); txn.put(entity);
txn.commit(); txn.commit();
} catch (DatastoreException ex) { } catch (DatastoreException ex) {
if (ex.getCode() == 10 && ex.getMessage().startsWith("too much contention")) { if (ex.getCode() == 10) {
return throwConflict(); return throwConflict();
} else } else
throw ex; throw ex;
...@@ -129,7 +129,7 @@ public class DatastoreActionRepo implements IActionRepo { ...@@ -129,7 +129,7 @@ public class DatastoreActionRepo implements IActionRepo {
output = true; output = true;
} }
} catch (DatastoreException ex) { } 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."); throw new AppException(409, "Conflict", "Another request is trying to delete the same DDMS.");
else else
throw ex; throw ex;
......
...@@ -64,7 +64,7 @@ public class DatastoreDdmsRepository implements IDdmsRepository { ...@@ -64,7 +64,7 @@ public class DatastoreDdmsRepository implements IDdmsRepository {
txn.put(entity); txn.put(entity);
txn.commit(); txn.commit();
} catch (DatastoreException ex) { } 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"); throw new AppException(409, "Conflict", "A DDMS already exists with the same id");
else else
throw ex; throw ex;
...@@ -118,7 +118,7 @@ public class DatastoreDdmsRepository implements IDdmsRepository { ...@@ -118,7 +118,7 @@ public class DatastoreDdmsRepository implements IDdmsRepository {
output = true; output = true;
} }
} catch (DatastoreException ex) { } 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."); throw new AppException(409, "Conflict", "Another request is trying to delete the same DDMS.");
else else
throw ex; throw ex;
......
...@@ -108,6 +108,7 @@ public class DatastoreAccess implements IDatastoreAccess { ...@@ -108,6 +108,7 @@ public class DatastoreAccess implements IDatastoreAccess {
@Override @Override
public List<Subscription> getAll() throws Exception { public List<Subscription> getAll() throws Exception {
Datastore ds = dataStoreTenants.get(tenantInfo.getName()); Datastore ds = dataStoreTenants.get(tenantInfo.getName());
Query<Entity> q = Query Query<Entity> q = Query
.newGqlQueryBuilder(Query.ResultType.ENTITY, "Select * from SUBSCRIPTION") .newGqlQueryBuilder(Query.ResultType.ENTITY, "Select * from SUBSCRIPTION")
...@@ -137,7 +138,7 @@ public class DatastoreAccess implements IDatastoreAccess { ...@@ -137,7 +138,7 @@ public class DatastoreAccess implements IDatastoreAccess {
txn.put(entity); txn.put(entity);
txn.commit(); txn.commit();
} catch (DatastoreException ex) { } 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"); throw new AppException(409, "Conflict", "A subscriber already exists with the same topic and endpoint combination");
else else
throw ex; throw ex;
...@@ -169,7 +170,7 @@ public class DatastoreAccess implements IDatastoreAccess { ...@@ -169,7 +170,7 @@ public class DatastoreAccess implements IDatastoreAccess {
output = true; output = true;
} }
} catch (DatastoreException ex) { } 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."); throw new AppException(409, "Conflict", "Another request is trying to delete the same DDMS.");
else else
throw ex; throw ex;
...@@ -198,7 +199,7 @@ public class DatastoreAccess implements IDatastoreAccess { ...@@ -198,7 +199,7 @@ public class DatastoreAccess implements IDatastoreAccess {
output = true; output = true;
} }
} catch (DatastoreException ex) { } 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."); throw new AppException(409, "Conflict", "Another request is trying to update the same subscription.");
else else
throw ex; 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