docs: better error handling in the code sample. thanks wgm.china for the report.