FBExceptionHandler.m 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /**
  2. * Copyright (c) 2015-present, Facebook, Inc.
  3. * All rights reserved.
  4. *
  5. * This source code is licensed under the BSD-style license found in the
  6. * LICENSE file in the root directory of this source tree. An additional grant
  7. * of patent rights can be found in the PATENTS file in the same directory.
  8. */
  9. #import "FBExceptionHandler.h"
  10. #import "RouteResponse.h"
  11. #import "FBResponsePayload.h"
  12. #import "FBExceptions.h"
  13. @implementation FBExceptionHandler
  14. - (void)handleException:(NSException *)exception forResponse:(RouteResponse *)response
  15. {
  16. FBCommandStatus *commandStatus;
  17. NSString *traceback = [NSString stringWithFormat:@"%@", exception.callStackSymbols];
  18. if ([exception.name isEqualToString:FBSessionDoesNotExistException]) {
  19. commandStatus = [FBCommandStatus noSuchDriverErrorWithMessage:exception.reason
  20. traceback:traceback];
  21. } else if ([exception.name isEqualToString:FBInvalidArgumentException]
  22. || [exception.name isEqualToString:FBElementAttributeUnknownException]
  23. || [exception.name isEqualToString:FBApplicationMissingException]) {
  24. commandStatus = [FBCommandStatus invalidArgumentErrorWithMessage:exception.reason
  25. traceback:traceback];
  26. } else if ([exception.name isEqualToString:FBApplicationCrashedException]
  27. || [exception.name isEqualToString:FBApplicationDeadlockDetectedException]) {
  28. commandStatus = [FBCommandStatus invalidElementStateErrorWithMessage:exception.reason
  29. traceback:traceback];
  30. } else if ([exception.name isEqualToString:FBInvalidXPathException]
  31. || [exception.name isEqualToString:FBClassChainQueryParseException]) {
  32. commandStatus = [FBCommandStatus invalidSelectorErrorWithMessage:exception.reason
  33. traceback:traceback];
  34. } else if ([exception.name isEqualToString:FBElementNotVisibleException]) {
  35. commandStatus = [FBCommandStatus elementNotVisibleErrorWithMessage:exception.reason
  36. traceback:traceback];
  37. } else if ([exception.name isEqualToString:FBStaleElementException]) {
  38. commandStatus = [FBCommandStatus staleElementReferenceErrorWithMessage:exception.reason
  39. traceback:traceback];
  40. } else if ([exception.name isEqualToString:FBTimeoutException]) {
  41. commandStatus = [FBCommandStatus timeoutErrorWithMessage:exception.reason
  42. traceback:traceback];
  43. } else if ([exception.name isEqualToString:FBSessionCreationException]) {
  44. commandStatus = [FBCommandStatus sessionNotCreatedError:exception.reason
  45. traceback:traceback];
  46. } else {
  47. commandStatus = [FBCommandStatus unknownErrorWithMessage:exception.reason
  48. traceback:traceback];
  49. }
  50. id<FBResponsePayload> payload = FBResponseWithStatus(commandStatus);
  51. [payload dispatchWithResponse:response];
  52. }
  53. @end