All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.hyperledger.fabric.shim.ChaincodeException Maven / Gradle / Ivy

There is a newer version: 2.5.3
Show newest version
/*
Copyright IBM Corp. All Rights Reserved.

SPDX-License-Identifier: Apache-2.0
*/
package org.hyperledger.fabric.shim;

import static java.nio.charset.StandardCharsets.UTF_8;

/**
 * Contracts should use {@code ChaincodeException} to indicate when an error
 * occurs in Smart Contract logic.
 *
 * 

* When a {@code ChaincodeException} is thrown an error response will be * returned from the chaincode container containing the exception message and * payload, if specified. * *

* {@code ChaincodeException} may be extended to provide application specific * error information. Subclasses should ensure that {@link #getPayload} returns * a serialized representation of the error in a suitable format for client * applications to process. */ public class ChaincodeException extends RuntimeException { private static final long serialVersionUID = 3664437023130016393L; private byte[] payload; /** * Constructs a new {@code ChaincodeException} with no detail message. */ public ChaincodeException() { super(); } /** * Constructs a new {@code ChaincodeException} with the specified detail * message. * * @param message the detail message. */ public ChaincodeException(String message) { super(message); } /** * Constructs a new {@code ChaincodeException} with the specified cause. * * @param cause the cause. */ public ChaincodeException(Throwable cause) { super(cause); } /** * Constructs a new {@code ChaincodeException} with the specified detail * message and cause. * * @param message the detail message. * @param cause the cause. */ public ChaincodeException(String message, Throwable cause) { super(message, cause); } /** * Constructs a new {@code ChaincodeException} with the specified detail * message and response payload. * * @param message the detail message. * @param payload the response payload. */ public ChaincodeException(String message, byte[] payload) { super(message); this.payload = payload; } /** * Constructs a new {@code ChaincodeException} with the specified detail * message, response payload and cause. * * @param message the detail message. * @param payload the response payload. * @param cause the cause. */ public ChaincodeException(String message, byte[] payload, Throwable cause) { super(message, cause); this.payload = payload; } /** * Constructs a new {@code ChaincodeException} with the specified detail * message and response payload. * * @param message the detail message. * @param payload the response payload. */ public ChaincodeException(String message, String payload) { super(message); this.payload = payload.getBytes(UTF_8); } /** * Constructs a new {@code ChaincodeException} with the specified detail * message, response payload and cause. * * @param message the detail message. * @param payload the response payload. * @param cause the cause. */ public ChaincodeException(String message, String payload, Throwable cause) { super(message, cause); this.payload = payload.getBytes(UTF_8); } /** * Returns the response payload or {@code null} if there is no response. * *

* The payload should represent the chaincode error in a way that client * applications written in different programming languages can interpret. For * example it could include a domain specific error code, in addition to any * state information which would allow client applications to respond * appropriately. * * @return the response payload or {@code null} if there is no response. */ public byte[] getPayload() { return payload; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy