PillowPillow / ng2-webstorage

Localstorage and sessionstorage manager - Angular service
MIT License
428 stars 91 forks source link

Clearing the storage manually in Chrome throws error #78

Closed ghiscoding closed 6 years ago

ghiscoding commented 6 years ago

I'm just trying out your lib and perhaps that might be me doing something wrong.

If I add some data in Local Storage and then I go manually clear the storage with Chrome, I get this error showing in the console

core.js:1350 ERROR TypeError: Cannot read property 'indexOf' of null
    at Function.KeyStorageHelper.isManagedKey (keyStorage.js:12)
    at Function.WebStorageHelper.refresh (webStorage.js:32)
    at eval (app.js:47)
    at ZoneDelegate.invoke (zone.js:392)
    at Object.onInvoke (core.js:4629)
    at ZoneDelegate.invoke (zone.js:391)
    at Zone.run (zone.js:142)
    at NgZone.run (core.js:4446)
    at eval (app.js:45)
    at ZoneDelegate.invokeTask (zone.js:425)

logging.service.ts:3 Cannot read property 'indexOf' of null /admin-user Function.KeyStorageHelper.isManagedKey()@webpack-internal:///../../../../ngx-webstorage/dist/helpers/keyStorage.js:15:21
Function.WebStorageHelper.refresh()@webpack-internal:///../../../../ngx-webstorage/dist/helpers/webStorage.js:38:84
eval()@webpack-internal:///../../../../ngx-webstorage/dist/app.js:62:99
ZoneDelegate.invoke()@webpack-internal:///../../../../zone.js/dist/zone.js:392:26
Object.onInvoke()@webpack-internal:///../../../core/esm5/core.js:4825:33
ZoneDelegate.invoke()@webpack-internal:///../../../../zone.js/dist/zone.js:391:32
Zone.run()@webpack-internal:///../../../../zone.js/dist/zone.js:142:43
NgZone.run()@webpack-internal:///../../../core/esm5/core.js:4642:69
eval()@webpack-internal:///../../../../ngx-webstorage/dist/app.js:60:37
ZoneDelegate.invokeTask()@webpack-internal:///../../../../zone.js/dist/zone.js:425:31

The error comes from a property that gets call and is undefined

storageerror

I guess this could be avoided by making sure the object exist on this line in keyStorage.ts, the same code is on line 9 and 15.

PillowPillow commented 6 years ago

Hello, thanks for this issue. I think it's related to #59. I'll check that later in the evening.

PillowPillow commented 6 years ago

Hello, the v2.0.1 should fix your issue. Please let me know if you encounter another issue.

ghiscoding commented 6 years ago

Almost forgot to reply back, that did fix it... so thanks a lot :)