17
17
package example ;
18
18
19
19
import static java .lang .String .format ;
20
- import static org .hyperledger .fabric .shim .ChaincodeHelper .newBadRequestResponse ;
21
- import static org .hyperledger .fabric .shim .ChaincodeHelper .newInternalServerErrorResponse ;
22
- import static org .hyperledger .fabric .shim .ChaincodeHelper .newSuccessResponse ;
23
20
24
21
import java .io .PrintWriter ;
25
22
import java .io .StringWriter ;
31
28
32
29
import org .apache .commons .logging .Log ;
33
30
import org .apache .commons .logging .LogFactory ;
34
- import org .hyperledger .fabric .protos .peer .ProposalResponsePackage .Response ;
35
31
import org .hyperledger .fabric .shim .ChaincodeBase ;
36
32
import org .hyperledger .fabric .shim .ChaincodeStub ;
37
33
@@ -49,14 +45,14 @@ public Response init(ChaincodeStub stub) {
49
45
case "init" :
50
46
return init (stub , args .stream ().skip (0 ).toArray (String []::new ));
51
47
default :
52
- return newBadRequestResponse (format ("Unknown function: %s" , args .get (0 )));
48
+ return newErrorResponse (format ("Unknown function: %s" , args .get (0 )));
53
49
}
54
50
} catch (NumberFormatException e ) {
55
- return newBadRequestResponse (e .toString ());
51
+ return newErrorResponse (e .toString ());
56
52
} catch (IllegalArgumentException e ) {
57
- return newBadRequestResponse (e .getMessage ());
53
+ return newErrorResponse (e .getMessage ());
58
54
} catch (Throwable e ) {
59
- return newInternalServerErrorResponse (e );
55
+ return newErrorResponse (e );
60
56
}
61
57
}
62
58
@@ -86,15 +82,15 @@ public Response invoke(ChaincodeStub stub) {
86
82
case "query" :
87
83
return query (stub , args );
88
84
default :
89
- return newBadRequestResponse (newErrorJson ("Unknown function: %s" , function ));
85
+ return newErrorResponse (newErrorJson ("Unknown function: %s" , function ));
90
86
}
91
87
92
88
} catch (NumberFormatException e ) {
93
- return newBadRequestResponse (e .toString ());
89
+ return newErrorResponse (e .toString ());
94
90
} catch (IllegalArgumentException e ) {
95
- return newBadRequestResponse (e .getMessage ());
91
+ return newErrorResponse (e .getMessage ());
96
92
} catch (Throwable e ) {
97
- return newInternalServerErrorResponse (e );
93
+ return newErrorResponse (e );
98
94
}
99
95
100
96
}
@@ -114,7 +110,7 @@ private Response invoke(ChaincodeStub stub, String[] args) {
114
110
stub .delState (arg );
115
111
return newSuccessResponse ();
116
112
default :
117
- return newBadRequestResponse (newErrorJson ("Unknown invoke sub-function: %s" , subFunction ));
113
+ return newErrorResponse (newErrorJson ("Unknown invoke sub-function: %s" , subFunction ));
118
114
}
119
115
}
120
116
0 commit comments