1717package example ;
1818
1919import 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 ;
2320
2421import java .io .PrintWriter ;
2522import java .io .StringWriter ;
3128
3229import org .apache .commons .logging .Log ;
3330import org .apache .commons .logging .LogFactory ;
34- import org .hyperledger .fabric .protos .peer .ProposalResponsePackage .Response ;
3531import org .hyperledger .fabric .shim .ChaincodeBase ;
3632import org .hyperledger .fabric .shim .ChaincodeStub ;
3733
@@ -49,14 +45,14 @@ public Response init(ChaincodeStub stub) {
4945 case "init" :
5046 return init (stub , args .stream ().skip (0 ).toArray (String []::new ));
5147 default :
52- return newBadRequestResponse (format ("Unknown function: %s" , args .get (0 )));
48+ return newErrorResponse (format ("Unknown function: %s" , args .get (0 )));
5349 }
5450 } catch (NumberFormatException e ) {
55- return newBadRequestResponse (e .toString ());
51+ return newErrorResponse (e .toString ());
5652 } catch (IllegalArgumentException e ) {
57- return newBadRequestResponse (e .getMessage ());
53+ return newErrorResponse (e .getMessage ());
5854 } catch (Throwable e ) {
59- return newInternalServerErrorResponse (e );
55+ return newErrorResponse (e );
6056 }
6157 }
6258
@@ -86,15 +82,15 @@ public Response invoke(ChaincodeStub stub) {
8682 case "query" :
8783 return query (stub , args );
8884 default :
89- return newBadRequestResponse (newErrorJson ("Unknown function: %s" , function ));
85+ return newErrorResponse (newErrorJson ("Unknown function: %s" , function ));
9086 }
9187
9288 } catch (NumberFormatException e ) {
93- return newBadRequestResponse (e .toString ());
89+ return newErrorResponse (e .toString ());
9490 } catch (IllegalArgumentException e ) {
95- return newBadRequestResponse (e .getMessage ());
91+ return newErrorResponse (e .getMessage ());
9692 } catch (Throwable e ) {
97- return newInternalServerErrorResponse (e );
93+ return newErrorResponse (e );
9894 }
9995
10096 }
@@ -114,7 +110,7 @@ private Response invoke(ChaincodeStub stub, String[] args) {
114110 stub .delState (arg );
115111 return newSuccessResponse ();
116112 default :
117- return newBadRequestResponse (newErrorJson ("Unknown invoke sub-function: %s" , subFunction ));
113+ return newErrorResponse (newErrorJson ("Unknown invoke sub-function: %s" , subFunction ));
118114 }
119115 }
120116
0 commit comments