Skip to content

Commit 7079208

Browse files
refactor: improve error message
1 parent f2d378f commit 7079208

1 file changed

Lines changed: 17 additions & 10 deletions

File tree

packages/core/src/consumed-thing.ts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,12 @@ export default class ConsumedThing extends TD.Thing implements IConsumedThing {
557557
form = this.handleUriVariables(tp, form, options);
558558

559559
const content = await client.readResource(form);
560-
return this.handleInteractionOutput(content, form, tp);
560+
try {
561+
return this.handleInteractionOutput(content, form, tp);
562+
} catch (e) {
563+
const error = e instanceof Error ? e : new Error(JSON.stringify(e));
564+
throw new Error(`Error while processing property for ${tp.title}. ${error.message}`);
565+
}
561566
}
562567

563568
private handleInteractionOutput(
@@ -578,11 +583,7 @@ export default class ConsumedThing extends TD.Thing implements IConsumedThing {
578583
);
579584
}
580585
}
581-
try {
582-
return new InteractionOutput(content, form, outputDataSchema);
583-
} catch {
584-
throw new Error(`Received invalid content from Thing`);
585-
}
586+
return new InteractionOutput(content, form, outputDataSchema);
586587
}
587588

588589
async _readProperties(propertyNames: string[]): Promise<WoT.PropertyReadMap> {
@@ -701,8 +702,12 @@ export default class ConsumedThing extends TD.Thing implements IConsumedThing {
701702
form = this.handleUriVariables(ta, form, options);
702703

703704
const content = await client.invokeResource(form, input);
704-
705-
return this.handleInteractionOutput(content, form, ta.output);
705+
try {
706+
return this.handleInteractionOutput(content, form, ta.output);
707+
} catch (e) {
708+
const error = e instanceof Error ? e : new Error(JSON.stringify(e));
709+
throw new Error(`Error while processing action for ${ta.title}. ${error.message}`);
710+
}
706711
}
707712

708713
/**
@@ -745,7 +750,8 @@ export default class ConsumedThing extends TD.Thing implements IConsumedThing {
745750
try {
746751
listener(new InteractionOutput(content, form, tp));
747752
} catch (e) {
748-
warn(`Error while processing observe event for ${tp.title}`);
753+
const error = e instanceof Error ? e : new Error(JSON.stringify(e));
754+
warn(`Error while processing observe property for ${tp.title}. ${error.message}`);
749755
warn(e);
750756
}
751757
},
@@ -802,7 +808,8 @@ export default class ConsumedThing extends TD.Thing implements IConsumedThing {
802808
try {
803809
listener(new InteractionOutput(content, form, te.data));
804810
} catch (e) {
805-
warn(`Error while processing event for ${te.title}`);
811+
const error = e instanceof Error ? e : new Error(JSON.stringify(e));
812+
warn(`Error while processing event for ${te.title}. ${error.message}`);
806813
warn(e);
807814
}
808815
},

0 commit comments

Comments
 (0)