OOError.swift 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. //
  2. // OOError.swift
  3. // o2app
  4. //
  5. // Created by 刘振兴 on 2017/8/24.
  6. // Copyright © 2017年 zone. All rights reserved.
  7. //
  8. import Foundation
  9. import Moya
  10. public enum OOAppError:Swift.Error {
  11. case imageMapping(message:String,statusCode:Int,data:Data?)
  12. case jsonMapping(message:String,statusCode:Int,data:Data?)
  13. case stringMapping(message:String,statusCode:Int,data:Data?)
  14. case statusCode(message:String,statusCode:Int,data:Data?)
  15. case underlying(Swift.Error)
  16. case requestMapping(String)
  17. case common(type:String,message:String,statusCode:Int)
  18. case objectMapping(Swift.Error,Response)
  19. case encodableMapping(Swift.Error)
  20. case parameterEncoding(Swift.Error)
  21. case apiResponseError(String)
  22. case apiEmptyResultError
  23. }
  24. extension OOAppError:LocalizedError {
  25. public var errorDescription: String? {
  26. switch self {
  27. case .imageMapping(let msg, let statusCode, _):
  28. return "Moya.Error:imageMapping,msg=\(msg),statusCode=\(statusCode)"
  29. case .jsonMapping(let msg, let statusCode, _):
  30. return "Moya.Error:jsonMapping,msg=\(msg),statusCode=\(statusCode)"
  31. case .stringMapping(let msg, let statusCode, _):
  32. return "Moya.Error:stringMapping,msg=\(msg),statusCode=\(statusCode)"
  33. case .statusCode(let msg, let statusCode, _):
  34. return "Moya.Error:statusCode,msg=\(msg),statusCode=\(statusCode)"
  35. case .underlying(let err):
  36. return "Moya.Error:underlying,error=\(err)"
  37. case .requestMapping(let msg):
  38. return "Moya.Error:requestMapping,msg=\(msg)"
  39. case .common(let type, let msg, let statusCode):
  40. return "App.Error:type=\(type),msg=\(msg),statusCode=\(statusCode)"
  41. case .objectMapping(let err, let resp):
  42. return "Moya.Error:objectMapping,error=\(err),resp=\(resp)"
  43. case .encodableMapping(let err):
  44. return "Moya.Error:encodableMapping,error=\(err)"
  45. case .parameterEncoding(let err):
  46. return "Moay.Error:parameterEncoding,error=\(err)"
  47. case .apiResponseError(let err):
  48. return "API.Error:apiResponseError,error=\(err)"
  49. case .apiEmptyResultError:
  50. return "API 返回结果为空"
  51. }
  52. }
  53. public var failureReason: String? {
  54. switch self {
  55. case .imageMapping(let msg,_,_):
  56. return msg
  57. case .jsonMapping(let msg, _,_):
  58. return msg
  59. case .stringMapping(let msg,_,_):
  60. return msg
  61. case .statusCode(let msg,_,_):
  62. return msg
  63. case .underlying(let err):
  64. return err.localizedDescription
  65. case .requestMapping(let msg):
  66. return msg
  67. case .common(_,let msg,_):
  68. return msg
  69. case .objectMapping(let err, let resp):
  70. return "error=\(err.localizedDescription),resp=\(resp)"
  71. case .encodableMapping(let err):
  72. return err.localizedDescription
  73. case .parameterEncoding(let err):
  74. return err.localizedDescription
  75. case .apiResponseError(let err):
  76. return err
  77. case .apiEmptyResultError:
  78. return "API 返回结果为空"
  79. }
  80. }
  81. }
  82. public enum OOError:Swift.Error {
  83. case systemError(Swift.Error)
  84. case appError(OOAppError)
  85. }