diff --git a/src/app/BufferedReadCallback.cpp b/src/app/BufferedReadCallback.cpp index 3752a3e65aef08..45fae2b39e8a1b 100644 --- a/src/app/BufferedReadCallback.cpp +++ b/src/app/BufferedReadCallback.cpp @@ -36,13 +36,8 @@ void BufferedReadCallback::OnReportBegin() void BufferedReadCallback::OnReportEnd() { - CHIP_ERROR err = DispatchBufferedData(mBufferedPath, StatusIB(), true); - if (err != CHIP_NO_ERROR) - { - mCallback.OnError(err); - return; - } - + mError = DispatchBufferedData(mBufferedPath, StatusIB(), true); + ReturnOnFailure(mError); mCallback.OnReportEnd(); } @@ -230,21 +225,19 @@ CHIP_ERROR BufferedReadCallback::DispatchBufferedData(const ConcreteAttributePat void BufferedReadCallback::OnAttributeData(const ConcreteDataAttributePath & aPath, TLV::TLVReader * apData, const StatusIB & aStatus) { - CHIP_ERROR err; - // // First, let's dispatch to our registered callback any buffered up list data from previous calls. // - err = DispatchBufferedData(aPath, aStatus); - SuccessOrExit(err); + mError = DispatchBufferedData(aPath, aStatus); + ReturnOnFailure(mError); // // We buffer up list data (only if the status was successful) // if (aPath.IsListOperation() && aStatus.mStatus == Protocols::InteractionModel::Status::Success) { - err = BufferData(aPath, apData); - SuccessOrExit(err); + mError = BufferData(aPath, apData); + ReturnOnFailure(mError); } else { @@ -255,12 +248,6 @@ void BufferedReadCallback::OnAttributeData(const ConcreteDataAttributePath & aPa // Update our latched buffered path. // mBufferedPath = aPath; - -exit: - if (err != CHIP_NO_ERROR) - { - mCallback.OnError(err); - } } } // namespace app diff --git a/src/app/BufferedReadCallback.h b/src/app/BufferedReadCallback.h index b24257884e1a77..28719613a6514f 100644 --- a/src/app/BufferedReadCallback.h +++ b/src/app/BufferedReadCallback.h @@ -43,6 +43,15 @@ class BufferedReadCallback : public ReadClient::Callback BufferedReadCallback(Callback & callback) : mCallback(callback) {} private: + + /* + * Retrieve the internal error in BufferedReadCallback + */ + CHIP_ERROR CheckInternalError() override + { + return mError; + } + /* * Generates the reconsistuted TLV array from the stored individual list elements */ @@ -74,6 +83,7 @@ class BufferedReadCallback : public ReadClient::Callback void OnError(CHIP_ERROR aError) override { mBufferedList.clear(); + mError = CHIP_NO_ERROR; return mCallback.OnError(aError); } @@ -131,6 +141,7 @@ class BufferedReadCallback : public ReadClient::Callback ConcreteDataAttributePath mBufferedPath; std::vector mBufferedList; Callback & mCallback; + CHIP_ERROR mError = CHIP_NO_ERROR; }; } // namespace app diff --git a/src/app/ReadClient.cpp b/src/app/ReadClient.cpp index 2d609eb1afa05a..d66468926528e2 100644 --- a/src/app/ReadClient.cpp +++ b/src/app/ReadClient.cpp @@ -805,6 +805,7 @@ CHIP_ERROR ReadClient::ProcessAttributeReportIBs(TLV::TLVReader & aAttributeRepo ReturnErrorOnFailure(errorStatus.DecodeStatusIB(statusIB)); NoteReportingData(); mpCallback.OnAttributeData(attributePath, nullptr, statusIB); + ReturnErrorOnFailure(mpCallback.CheckInternalError()); } else if (CHIP_END_OF_TLV == err) { diff --git a/src/app/ReadClient.h b/src/app/ReadClient.h index d8b8a971db8c28..2c1d4a06a158fe 100644 --- a/src/app/ReadClient.h +++ b/src/app/ReadClient.h @@ -284,6 +284,12 @@ class ReadClient : public Messaging::ExchangeDelegate * things like min/max intervals based on the session parameters). */ virtual void OnCASESessionEstablished(const SessionHandle & aSession, ReadPrepareParams & aSubscriptionParams) {} + + /* + * return the internal fatal error in callback + */ + virtual CHIP_ERROR CheckInternalError() { return CHIP_NO_ERROR; } + }; enum class InteractionType : uint8_t