feat(sdk)!: Use StreamrClientError instead of StreamMessagError
#2927
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a breaking change
Use
StreamrClientErrorinstead ofStreamMessageError:streamMessageparameter toStreamrClientErrorCodeInvalidJsonErrorremoved, usingINVALID_MESSAGE_CONTENTerror code insteadINVALID_SIGNATUREINVALID_PARTITIONASSERTION_FAILEDStreamMessageobject, we can assume thatStreamMessageinstance has a valid value for themessageTypeproperty as all instances are created by our internalStreamMessageTranslatorutility. We have aswitchstatement for handling different message types, and there we can throw an error withASSERTION_FAILEDcode ifmessageTypeis not any of the valid message types.MISSING_PERMISSIONerror codeRemoved
StreamMessageErrorclass.The
StreamrClientErrorclass has an optional constructor parameter for specifying relatedStreamMessage. When that is used, the error message contains a string representation of theMessageID. TheMessageIDis also stored to the error object as a field to make it accessible programmatically.StreamMessagErrorstored the wholeStreamMessageobject. Therefore e.g. the whole message content was exposed if the error was logged. This change resolves issue NET-1378.Also
codeis now included in the error message. It is good to duplicate thecodeandmessageIdinfo in the error message as custom error fields are not shown e.g. in browser environment outputs.Output in logs
In the NodeJS an error is written to the output like this:
In browser environments an error is written to the output like this:
Note that e.g. in NodeJS logs the
messageIdinfo is duplicated. In some other environments only the error message is visible, it is good to have the info also in the message.Open questions
Maybe this is not a breaking changes as we've not documented our errors? I.e. this is functionality change but but an API change.
Note
The change implemented in 6c5f4fcc6 is maybe not needed at all? Should improve test coverage and maybe remove the
ignoreMessagesfunctionality (if theonErroris never called with theStreamMessageparameter?)Future improvements
ValidationErrorand useStreamrClientErrorinstead of thatnew Error('streamId required')) withStreamrClientError