errors.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // Copyright 2015 The go-ethereum Authors
  2. // This file is part of the go-ethereum library.
  3. //
  4. // The go-ethereum library is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Lesser General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // The go-ethereum library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Lesser General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Lesser General Public License
  15. // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
  16. package rpc
  17. import "fmt"
  18. // request is for an unknown service
  19. type methodNotFoundError struct {
  20. service string
  21. method string
  22. }
  23. func (e *methodNotFoundError) Code() int {
  24. return -32601
  25. }
  26. func (e *methodNotFoundError) Error() string {
  27. return fmt.Sprintf("The method %s%s%s does not exist/is not available", e.service, serviceMethodSeparator, e.method)
  28. }
  29. // received message isn't a valid request
  30. type invalidRequestError struct {
  31. message string
  32. }
  33. func (e *invalidRequestError) Code() int {
  34. return -32600
  35. }
  36. func (e *invalidRequestError) Error() string {
  37. return e.message
  38. }
  39. // received message is invalid
  40. type invalidMessageError struct {
  41. message string
  42. }
  43. func (e *invalidMessageError) Code() int {
  44. return -32700
  45. }
  46. func (e *invalidMessageError) Error() string {
  47. return e.message
  48. }
  49. // unable to decode supplied params, or an invalid number of parameters
  50. type invalidParamsError struct {
  51. message string
  52. }
  53. func (e *invalidParamsError) Code() int {
  54. return -32602
  55. }
  56. func (e *invalidParamsError) Error() string {
  57. return e.message
  58. }
  59. // logic error, callback returned an error
  60. type callbackError struct {
  61. message string
  62. }
  63. func (e *callbackError) Code() int {
  64. return -32000
  65. }
  66. func (e *callbackError) Error() string {
  67. return e.message
  68. }
  69. // issued when a request is received after the server is issued to stop.
  70. type shutdownError struct {
  71. }
  72. func (e *shutdownError) Code() int {
  73. return -32000
  74. }
  75. func (e *shutdownError) Error() string {
  76. return "server is shutting down"
  77. }