SRError.m 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. //
  2. // Copyright (c) 2016-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 "SRError.h"
  10. #import "SRWebSocket.h"
  11. NS_ASSUME_NONNULL_BEGIN
  12. NSError *SRErrorWithDomainCodeDescription(NSString *domain, NSInteger code, NSString *description)
  13. {
  14. return [NSError errorWithDomain:domain code:code userInfo:@{ NSLocalizedDescriptionKey: description }];
  15. }
  16. NSError *SRErrorWithCodeDescription(NSInteger code, NSString *description)
  17. {
  18. return SRErrorWithDomainCodeDescription(SRWebSocketErrorDomain, code, description);
  19. }
  20. NSError *SRErrorWithCodeDescriptionUnderlyingError(NSInteger code, NSString *description, NSError *underlyingError)
  21. {
  22. return [NSError errorWithDomain:SRWebSocketErrorDomain
  23. code:code
  24. userInfo:@{ NSLocalizedDescriptionKey: description,
  25. NSUnderlyingErrorKey: underlyingError }];
  26. }
  27. NSError *SRHTTPErrorWithCodeDescription(NSInteger httpCode, NSInteger errorCode, NSString *description)
  28. {
  29. return [NSError errorWithDomain:SRWebSocketErrorDomain
  30. code:errorCode
  31. userInfo:@{ NSLocalizedDescriptionKey: description,
  32. SRHTTPResponseErrorKey: @(httpCode) }];
  33. }
  34. NS_ASSUME_NONNULL_END