Change signature for API to make possible handle errors by pattern matching