1414// You should have received a copy of the GNU Affero General Public License
1515// along with this program. If not, see <https://www.gnu.org/licenses/>.
1616
17+ use std:: fmt;
18+
1719use ccore:: Error as CoreError ;
1820use kvdb:: Error as KVDBError ;
1921use rlp:: DecoderError ;
2022
2123use jsonrpc_core:: { Error , ErrorCode , Value } ;
2224
2325mod codes {
26+ pub const NO_AUTHOR : i64 = -32002 ;
2427 pub const NO_WORK_REQUIRED : i64 = -32004 ;
2528 pub const UNKNOWN_ERROR : i64 = -32009 ;
2629 pub const PARCEL_ERROR : i64 = -32010 ;
@@ -61,6 +64,14 @@ pub fn rlp(error: DecoderError) -> Error {
6164 }
6265}
6366
67+ pub fn no_author ( ) -> Error {
68+ Error {
69+ code : ErrorCode :: ServerError ( codes:: NO_AUTHOR ) ,
70+ message : "Author not configured. Run Parity with --author to configure." . into ( ) ,
71+ data : None ,
72+ }
73+ }
74+
6475pub fn no_work_required ( ) -> Error {
6576 Error {
6677 code : ErrorCode :: ServerError ( codes:: NO_WORK_REQUIRED ) ,
@@ -76,3 +87,14 @@ pub fn network_disabled() -> Error {
7687 data : None ,
7788 }
7889}
90+
91+ /// Internal error signifying a logic error in code.
92+ /// Should not be used when function can just fail
93+ /// because of invalid parameters or incomplete node state.
94+ pub fn internal < T : fmt:: Debug > ( error : & str , data : T ) -> Error {
95+ Error {
96+ code : ErrorCode :: InternalError ,
97+ message : format ! ( "Internal error occurred: {}" , error) ,
98+ data : Some ( Value :: String ( format ! ( "{:?}" , data) ) ) ,
99+ }
100+ }
0 commit comments