-
Notifications
You must be signed in to change notification settings - Fork 117
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
Clearer error messages in read-only properties set attemps #14
Comments
Can you explain a use case where you would accidentally set one of these properties such as |
I forgot about this issue completely :P What I meant is, that const failSet = way => () => throw new Error('Cannot set read-only property R2.${way}') // <-- see this
const resolveResWith = way => resp => resp.clone()[way]()
/* formData isn't implemented in the shim yet */
const ways = ['json', 'text', 'arrayBuffer', 'blob', 'formData']
ways.forEach(way =>
Object.defineProperty(this, way, {
get: () => this.response.then(resolveResWith(way)),
set: failSet(way) // <-- fail set will tell you what read-only property you tried to change
})
) |
gotcha, thanks for following up after all this time 👍 I’ll leave this open but I think it will become obsolete as we will move away from the getters and use functions instead in a future version, as discussed in #22 |
@gr2m got it 😄 methods are definitely the better solution over getters+(unwanted)setters. I'm not using the library now, I don't even remember when I had to use it, but I'm glad that good design decisions are taken nonetheless. Keep it up 👍 |
Currently, failSet does not expose what property you tried to set.
My suggestion:
this way, the error that will be thrown will allow for quicker and easier debugging, since you'll more easily know what to search for in your code.
The text was updated successfully, but these errors were encountered: