github.com/muhammedhassanm/blockchain@v0.0.0-20200120143007-697261defd4d/sawtooth-core-master/sdk/javascript/processor/exceptions.js (about) 1 /** 2 * Copyright 2016 Intel Corporation 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 * ------------------------------------------------------------------------------ 16 */ 17 18 'use strict' 19 20 class _TransactionProcessorError extends Error { 21 constructor (message = '', extendedData = null) { 22 super(message) 23 this.name = this.constructor.name 24 25 if (extendedData) { 26 if (Buffer.isBuffer(extendedData) || extendedData instanceof Uint8Array) { 27 this.extendedData = extendedData 28 } else { 29 throw new TypeError('extendedData must be a Buffer or a Uint8Array') 30 } 31 } 32 } 33 } 34 35 /** 36 * Thrown for an Invalid Transaction. 37 */ 38 class InvalidTransaction extends _TransactionProcessorError { 39 /** 40 * Constructs a new InvalidTransaction. 41 * 42 * @param {string} [message] - an optional message, defaults to the empty 43 * string 44 * @param {Buffer|Uint8Array} [extendedData] - optional, application-specific 45 * serialized data to returned to the transaction submitter. 46 */ 47 constructor (message, extendedData) { 48 super(message, extendedData) 49 this.name = this.constructor.name 50 } 51 } 52 53 /** 54 * Thrown when an internal error occurs during transaction processing. 55 */ 56 class InternalError extends _TransactionProcessorError { 57 /** 58 * Constructs a new InternalError 59 * @param {string} [message] - an optional message, defaults to the empty 60 * string 61 * @param {Buffer|Uint8Array} [extendedData] - optional, application-specific 62 * serialized data to returned to the transaction submitter. 63 */ 64 constructor (message, extendedData) { 65 super(message, extendedData) 66 this.name = this.constructor.name 67 } 68 } 69 70 /** 71 * Thrown when a connection error occurs between the validator and the 72 * transaction processor. 73 */ 74 class ValidatorConnectionError extends Error { 75 /** 76 * Construcs a new ValidatorConnectionError 77 * 78 * @param {string} [message] - an optional message, defaults to the empty 79 * string 80 */ 81 constructor (message = '') { 82 super(message) 83 this.name = this.constructor.name 84 } 85 } 86 87 /** 88 * Thrown when a authorization error occurs. 89 */ 90 class AuthorizationException extends Error { 91 /** 92 * Construcs a new AuthorizationException 93 * 94 * @param {string} [message] - an optional message, defaults to the empty 95 * string 96 */ 97 constructor (message = '') { 98 super(message) 99 this.name = this.constructor.name 100 } 101 } 102 103 module.exports = { 104 InvalidTransaction, 105 InternalError, 106 ValidatorConnectionError, 107 AuthorizationException 108 }