/** * Copyright (c) 2015-present, Facebook, Inc. * All rights reserved. * * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. */ #import "FBExceptionHandler.h" #import #import "FBAlert.h" #import "FBResponsePayload.h" #import "FBSession.h" #import "FBXPath.h" #import "XCUIElement+FBClassChain.h" NSString *const FBInvalidArgumentException = @"FBInvalidArgumentException"; NSString *const FBSessionDoesNotExistException = @"FBSessionDoesNotExistException"; NSString *const FBApplicationDeadlockDetectedException = @"FBApplicationDeadlockDetectedException"; NSString *const FBElementAttributeUnknownException = @"FBElementAttributeUnknownException"; @implementation FBExceptionHandler - (BOOL)webServer:(FBWebServer *)webServer handleException:(NSException *)exception forResponse:(RouteResponse *)response { if ([exception.name isEqualToString:FBApplicationDeadlockDetectedException]) { id payload = FBResponseWithStatus(FBCommandStatusApplicationDeadlockDetected, [exception description]); [payload dispatchWithResponse:response]; return YES; } if ([exception.name isEqualToString:FBSessionDoesNotExistException]) { id payload = FBResponseWithStatus(FBCommandStatusNoSuchSession, [exception description]); [payload dispatchWithResponse:response]; return YES; } if ([exception.name isEqualToString:FBInvalidArgumentException]) { id payload = FBResponseWithStatus(FBCommandStatusInvalidArgument, [exception description]); [payload dispatchWithResponse:response]; return YES; } if ([exception.name isEqualToString:FBElementAttributeUnknownException]) { id payload = FBResponseWithStatus(FBCommandStatusInvalidSelector, [exception description]); [payload dispatchWithResponse:response]; return YES; } if ([exception.name isEqualToString:FBAlertObstructingElementException]) { id payload = FBResponseWithStatus(FBCommandStatusUnexpectedAlertPresent, @"Alert is obstructing view"); [payload dispatchWithResponse:response]; return YES; } if ([exception.name isEqualToString:FBApplicationCrashedException]) { id payload = FBResponseWithStatus(FBCommandStatusApplicationCrashDetected, [exception description]); [payload dispatchWithResponse:response]; return YES; } if ([exception.name isEqualToString:FBInvalidXPathException]) { id payload = FBResponseWithStatus(FBCommandStatusInvalidXPathSelector, [exception description]); [payload dispatchWithResponse:response]; return YES; } if ([exception.name isEqualToString:FBClassChainQueryParseException]) { id payload = FBResponseWithStatus(FBCommandStatusInvalidSelector, [exception description]); [payload dispatchWithResponse:response]; return YES; } return NO; } @end