Skip to content

Commit

Permalink
Isolate duplicated code in DatabasesManager.
Browse files Browse the repository at this point in the history
Reviewed By: lblasa

Differential Revision: D48316900

fbshipit-source-id: 2ae984f0d6f10b9cb843a74f335c77428d2229ef
  • Loading branch information
Fúlvio Abrahão de Paula authored and facebook-github-bot committed Aug 14, 2023
1 parent d102ae2 commit 661ed9e
Showing 1 changed file with 22 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,13 @@ - (void)listenForCommands {
DatabaseGetTableDataRequest* request = [DatabaseGetTableDataRequest
getTableDataRequestFromDictionary:params];
if (!request) {
NSDictionary* errorResponse = [ObjectMapper
errorWithCode:DatabasesErrorCodesInvalidRequest
message:kDatabasesErrorCodesInvalidRequestMessage];
[responder error:errorResponse];
[DatabasesManager raiseInvalidRequestError:responder];
return;
}
DatabaseDescriptorHolder* descriptorHolder =
self.databaseDescriptorHolders[@(request.databaseId)];
if (!descriptorHolder) {
NSDictionary* errorResponse = [ObjectMapper
errorWithCode:DatabasesErrorCodesDatabaseInvalid
message:kDatabasesErrorCodesDatabaseInvalidMessage];
[responder error:errorResponse];
[DatabasesManager raiseDatabaseInvalidError:responder];
return;
}

Expand Down Expand Up @@ -137,20 +131,13 @@ - (void)listenForCommands {
getTableStructureRequestFromDictionary:params];

if (!request) {
NSDictionary* errorResponse = [ObjectMapper
errorWithCode:DatabasesErrorCodesInvalidRequest
message:kDatabasesErrorCodesInvalidRequestMessage];
[responder error:errorResponse];
[DatabasesManager raiseInvalidRequestError:responder];
return;
}

DatabaseDescriptorHolder* descriptorHolder =
self.databaseDescriptorHolders[@(request.databaseId)];
if (!descriptorHolder) {
NSDictionary* errorResponse = [ObjectMapper
errorWithCode:DatabasesErrorCodesDatabaseInvalid
message:kDatabasesErrorCodesDatabaseInvalidMessage];
[responder error:errorResponse];
[DatabasesManager raiseDatabaseInvalidError:responder];
return;
}

Expand Down Expand Up @@ -178,19 +165,13 @@ - (void)listenForCommands {
DatabaseGetTableInfoRequest* request = [DatabaseGetTableInfoRequest
getTableInfoRequestFromDictionary:params];
if (!request) {
NSDictionary* errorResponse = [ObjectMapper
errorWithCode:DatabasesErrorCodesInvalidRequest
message:kDatabasesErrorCodesInvalidRequestMessage];
[responder error:errorResponse];
[DatabasesManager raiseInvalidRequestError:responder];
return;
}
DatabaseDescriptorHolder* descriptorHolder =
self.databaseDescriptorHolders[@(request.databaseId)];
if (!descriptorHolder) {
NSDictionary* errorResponse = [ObjectMapper
errorWithCode:DatabasesErrorCodesDatabaseInvalid
message:kDatabasesErrorCodesDatabaseInvalidMessage];
[responder error:errorResponse];
[DatabasesManager raiseDatabaseInvalidError:responder];
return;
}

Expand Down Expand Up @@ -218,19 +199,13 @@ - (void)listenForCommands {
DatabaseExecuteSqlRequest* request = [DatabaseExecuteSqlRequest
getExecuteSqlRequestFromDictionary:params];
if (!request) {
NSDictionary* errorResponse = [ObjectMapper
errorWithCode:DatabasesErrorCodesInvalidRequest
message:kDatabasesErrorCodesInvalidRequestMessage];
[responder error:errorResponse];
[DatabasesManager raiseInvalidRequestError:responder];
return;
}
DatabaseDescriptorHolder* descriptorHolder =
self.databaseDescriptorHolders[@(request.databaseId)];
if (!descriptorHolder) {
NSDictionary* errorResponse = [ObjectMapper
errorWithCode:DatabasesErrorCodesDatabaseInvalid
message:kDatabasesErrorCodesDatabaseInvalidMessage];
[responder error:errorResponse];
[DatabasesManager raiseDatabaseInvalidError:responder];
return;
}
@try {
Expand All @@ -249,4 +224,18 @@ - (void)listenForCommands {
}];
}

+ (void)raiseInvalidRequestError:(id<FlipperResponder>)responder {
NSDictionary* errorResponse =
[ObjectMapper errorWithCode:DatabasesErrorCodesInvalidRequest
message:kDatabasesErrorCodesInvalidRequestMessage];
[responder error:errorResponse];
}

+ (void)raiseDatabaseInvalidError:(id<FlipperResponder>)responder {
NSDictionary* errorResponse =
[ObjectMapper errorWithCode:DatabasesErrorCodesDatabaseInvalid
message:kDatabasesErrorCodesDatabaseInvalidMessage];
[responder error:errorResponse];
}

@end

0 comments on commit 661ed9e

Please sign in to comment.