fix!: Ensure data in response is always empty on error (#24971)

This commit is contained in:
Koen Kanters
2024-12-01 20:11:34 +01:00
parent d78c6facab
commit a6b36051f0
3 changed files with 10 additions and 9 deletions
+2 -1
View File
@@ -121,7 +121,8 @@ function getObjectProperty<T>(object: KeyValue, key: string, defaultValue: NoInf
}
function getResponse(request: KeyValue | string, data: KeyValue, error?: string): MQTTResponse {
const response: MQTTResponse = {data, status: error ? 'error' : 'ok'};
// On `error`, always return an empty `data` payload.
const response: MQTTResponse = {data: error ? {} : data, status: error ? 'error' : 'ok'};
if (error) {
response.error = error;