PageRenderTime 8932ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/src/Evm.Rtl/src/Evm/Rtl/InvokeResult.scala

https://bitbucket.org/yuanxu/sevm
Scala | 76 lines | 28 code | 15 blank | 33 comment | 2 complexity | e7599a0744902e5ff2395b031305e103 MD5 | raw file
  1. package evm.rtl
  2. import com.alibaba.fastjson.JSON
  3. import scala.reflect.BeanProperty
  4. /**
  5. * 调用结果
  6. */
  7. class InvokeResult(@BeanProperty val errorCode: Int, @BeanProperty val errorMessage: String, @BeanProperty val data: Any) {
  8. /**
  9. * 成功无数据
  10. */
  11. def this() = this(0, "", null)
  12. /**
  13. * 包含成功数据
  14. */
  15. def this(data: Any) = this(0, "", data)
  16. /**
  17. * 错误
  18. */
  19. def this(errorCode: Int, errorMessage: String) = this(errorCode, errorMessage, null)
  20. def this(errorCode: Int) = this(errorCode, "", null)
  21. @BeanProperty
  22. val isSucceed = errorCode == 0
  23. @BeanProperty
  24. val isError = errorCode != 0
  25. /**
  26. * 转换为Json
  27. */
  28. def toJson = JSON.toJSONString(this, true)
  29. }
  30. /**
  31. * 类型解析错误
  32. */
  33. class InvokeTypeResolveError(typeName: String) extends InvokeResult(-1, format("Resolve Type %s Exception.", typeName)) {
  34. def this() = this("")
  35. }
  36. /**
  37. * 未找到方法
  38. */
  39. class InvokeMethodNotFoundError(method: String) extends InvokeResult(-2, format("Method %s Not Found Exception", method)) {
  40. def this() = this("")
  41. }
  42. /**
  43. * 参数错误
  44. */
  45. class InvokeArgumentException(message:String) extends InvokeResult(-3,message){
  46. def this() = this("Arguments Null Exception")
  47. }
  48. /**
  49. * 验证错误
  50. */
  51. class InvokeAuthenticationError extends InvokeResult(-4,"Authentication Error")
  52. /**
  53. * 鉴权错误
  54. */
  55. class InvokeAuthorizationError extends InvokeResult(-5,"Authorization error")
  56. /**
  57. * 未知错误
  58. */
  59. class InvokeUnknownException(message:String) extends InvokeResult(-1000,format("Unknown Error!\r\n%s",message)){
  60. def this()=this("")
  61. }