void HeaderServerChannel::Stream::timeoutExpired() noexcept { TTransportException error(TTransportException::TIMED_OUT, "Receive Expired"); std::exception_ptr errorPtr = std::make_exception_ptr(error); manager_->notifyError(errorPtr); TApplicationException serializableError( TApplicationException::TApplicationExceptionType::TIMEOUT, "Task expired"); channel_->header_->setHeader("ex", "1"); auto errorBuffer = serializeError(channel_->header_->getProtocolId(), serializableError, buffer_.get()); channel_->sendMessage(nullptr, std::move(errorBuffer)); deleteThisIfNecessary(); }
/** * Send a serialized error back to the client. * For a header server, this means serializing the exception, and setting * an error flag in the header. */ void HeaderServerChannel::HeaderRequest::sendError( std::exception_ptr ep, std::string exCode, MessageChannel::SendCallback* cb) { try { std::rethrow_exception(ep); } catch (const TApplicationException& ex) { channel_->header_->setHeader("ex", exCode); std::unique_ptr<folly::IOBuf> exbuf( serializeError(channel_->header_->getProtocolId(), ex, getBuf())); sendReply(std::move(exbuf), cb); } catch (const std::exception& ex) { // Other types are unimplemented. DCHECK(false); } }
void serializeCheckType(int type, int expected) { if(type != expected) { serializeError(Error_Serialization_TypeMismatch); } }