add error cases to the test
fix error handling
always return `undefined`