T
TanStack12mo ago
evident-indigo

handleSerialError fails when setting err.routerCode with TypeError(s)

Fetch network requests or other fetch errors that don't even bring a response are automatically TypeError, and that object can't be extended, causing: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Cant_define_property_object_not_extensible
MDN Web Docs
TypeError: can't define property "x": "obj" is not extensible - Jav...
The JavaScript exception "can't define property "x": "obj" is not extensible" occurs when Object.preventExtensions() marked an object as no longer extensible, so that it will never have properties beyond the ones it had at the time it was marked as non-extensible.
3 Replies
evident-indigo
evident-indigoOP12mo ago
Fetch network requests or other fetch errors that don't even bring a response are automatically TypeError, and that object can't be extended, causing: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Cant_define_property_object_not_extensible
MDN Web Docs
TypeError: can't define property "x": "obj" is not extensible - Jav...
The JavaScript exception "can't define property "x": "obj" is not extensible" occurs when Object.preventExtensions() marked an object as no longer extensible, so that it will never have properties beyond the ones it had at the time it was marked as non-extensible.
evident-indigo
evident-indigoOP12mo ago
The solution is to wrap fetch network/cors errors into your own, e.g.:
class FetchTypeError extends Error {
constructor(public error: Error) {
super(error.message, { cause: error });
this.name = 'FetchTypeError';
}
}
class FetchTypeError extends Error {
constructor(public error: Error) {
super(error.message, { cause: error });
this.name = 'FetchTypeError';
}
}
However this feels like an imposition on the router part just because err.routerCode is being set by the error handler. Perhaps a warning would be helfpul.
harsh-harlequin
harsh-harlequin12mo ago
can you please provide a minimal example for this ?

Did you find this page helpful?