fix problem when the resource was already deleted.

[TODO]
- improve unittest