Skip to content

Commit

Permalink
Create helper function to handle PreprocessResult
Browse files Browse the repository at this point in the history
Summary: Simplify code

Reviewed By: robertroeser

Differential Revision: D67296408

fbshipit-source-id: 759086d5860438637df3b3219a7f958bc000a417
  • Loading branch information
Akrama Baig Mirza authored and facebook-github-bot committed Dec 19, 2024
1 parent 957ea84 commit 7f3dba7
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -649,42 +649,11 @@ void ThriftRocketServerHandler::handleRequestCommon(
auto preprocessResult =
serverConfigs_->preprocess({headers, name, connContext_, request.get()});
if (UNLIKELY(!std::holds_alternative<std::monostate>(preprocessResult))) {
folly::variant_match(
preprocessResult,
[&](AppClientException& ace) {
handleAppError(std::move(request), ace);
},
[&](const AppServerException& ase) {
handleAppError(std::move(request), ase);
},
[&](AppOverloadedException& aoe) {
std::string_view exCode = kAppOverloadedErrorCode;
if ((interactionCreateOpt || interactionIdOpt) &&
shouldTerminateInteraction(
interactionCreateOpt.has_value(),
interactionIdOpt,
&connContext_)) {
exCode = kInteractionLoadsheddedAppOverloadErrorCode;
}
handleRequestOverloadedServer(
std::move(request),
OverloadResult{
std::string(exCode), aoe.getMessage(), LoadShedder::CUSTOM});
},
[&](AppQuotaExceededException& aqe) {
handleQuotaExceededException(
std::move(request),
kTenantQuotaExceededErrorCode,
aqe.getMessage());
},
[&](AppTenantBlocklistedException& atb) {
handleQuotaExceededException(
std::move(request),
kTenantBlocklistedErrorCode,
atb.getMessage());
},
[](std::monostate&) { folly::assume_unreachable(); });

handlePreprocessResult(
std::move(request),
std::move(preprocessResult),
interactionCreateOpt.has_value(),
interactionIdOpt);
return;
}

Expand Down Expand Up @@ -750,6 +719,42 @@ void ThriftRocketServerHandler::handleRequestCommon(
worker_->getServer());
}

void ThriftRocketServerHandler::handlePreprocessResult(
ThriftRequestCoreUniquePtr request,
PreprocessResult&& preprocessResult,
bool isInteractionCreatePresent,
std::optional<int64_t>& interactionIdOpt) {
folly::variant_match(
preprocessResult,
[&](AppClientException& ace) { handleAppError(std::move(request), ace); },
[&](const AppServerException& ase) {
handleAppError(std::move(request), ase);
},
[&](AppOverloadedException& aoe) {
std::string_view exCode = kAppOverloadedErrorCode;
if ((isInteractionCreatePresent || interactionIdOpt) &&
shouldTerminateInteraction(
isInteractionCreatePresent, interactionIdOpt, &connContext_)) {
exCode = kInteractionLoadsheddedAppOverloadErrorCode;
}
handleRequestOverloadedServer(
std::move(request),
OverloadResult{
std::string(exCode), aoe.getMessage(), LoadShedder::CUSTOM});
},
[&](AppQuotaExceededException& aqe) {
handleQuotaExceededException(
std::move(request),
kTenantQuotaExceededErrorCode,
aqe.getMessage());
},
[&](AppTenantBlocklistedException& atb) {
handleQuotaExceededException(
std::move(request), kTenantBlocklistedErrorCode, atb.getMessage());
},
[](std::monostate&) { folly::assume_unreachable(); });
}

void ThriftRocketServerHandler::handleRequestWithBadMetadata(
ThriftRequestCoreUniquePtr request) {
if (auto* observer = serverConfigs_->getObserver()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ class ThriftRocketServerHandler : public RocketServerHandler {
RpcKind expectedKind,
bool decodeMetadataUsingBinary);

FOLLY_NOINLINE void handlePreprocessResult(
ThriftRequestCoreUniquePtr request,
PreprocessResult&& preprocessResult,
bool isInteractionCreatePresent,
std::optional<int64_t>& interactionId);
FOLLY_NOINLINE void handleRequestWithBadMetadata(
ThriftRequestCoreUniquePtr request);
FOLLY_NOINLINE void handleRequestWithBadChecksum(
Expand Down

0 comments on commit 7f3dba7

Please sign in to comment.