Handle domain error in write function
Test write function against error from API