add onsuccess and onerror hooks