-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: handle also enhanced contentTypes #1251
Conversation
e.g., expected "application/json" should deal with "application/json; charset=utf-8"
Question: is it enough to look into the contentType before ":" Note1: I assume if we have Note2: I assume we want to have the same check for properties/events as well, right? |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1251 +/- ##
==========================================
+ Coverage 77.81% 77.84% +0.02%
==========================================
Files 84 84
Lines 17523 17541 +18
Branches 1781 1783 +2
==========================================
+ Hits 13635 13654 +19
+ Misses 3853 3852 -1
Partials 35 35 ☔ View full report in Codecov by Sentry. |
How about checking for string inclusion instead? |
I think to get it right we might want to use a dedicated library like I fear that there might be some edge cases we miss otherwise... |
Note: I updated accordingly
|
I like the overall changes. Do we want to apply this to all interaction styles in this PR? In the long run, all should use this library. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me in general :) See one relatively minor comment below:
Co-authored-by: Jan Romann <jan.romann@uni-bremen.de>
01e0b84 adds the same handling for observeProperty and event |
try { | ||
return this.handleInteractionOutput(content, form, tp); | ||
} catch (e) { | ||
const error = e instanceof Error ? e : new Error(JSON.stringify(e)); | ||
throw new Error(`Error while processing property for ${tp.title}. ${error.message}`); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am wondering if we could maybe also simplify these try-catch-blocks, as the handleInteractionOutput
method itself is probably the only place where an error could originate from, right? But this would only be an optimization step.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking about the same. In the first commits the try catch
block was inside handleInteractionOutput()
.
The downside was/is that either the error message is not very clear (not stating for which interaction name & type it originates from) OR we need to pass additional arguments like interaction-type (property, action, event) and interaction-name is used to handleInteractionOutput()
purely for logging.
Personally I didn't like that much and hence decided to do the error handling in each interaction even though I know it duplicates code.
Anyhow, I am open to either way...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The downside was/is that either the error message is not very clear (not stating for which interaction name & type it originates from) OR we need to pass additional arguments like interaction-type (property, action, event) and interaction-name is used to handleInteractionOutput() purely for logging.
Personally I didn't like that much and hence decided to do the error handling in each interaction even though I know it duplicates code.
Yeah, I agree, passing these parameters only for logging is definitely not that ideal. So I think we can keep it as is :) Maybe one potential solution for the future could be introducing a common interface for ConsumedThingProperty
, ConsumedThingAction
, ConsumedThinEvent
and then passing the respective interaction affordance to the handler function which could then obtain the necessary information for logging.
Is there anything else I can/should do? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general, I'm a little bit reluctant to add external libraries to the core package unless they are really something needed. However, in this case, I can make an exception given the fact that the package is really just one single file. We can merge!
e.g., expected "application/json" should deal with "application/json; charset=utf-8"
fixes #1250