Add proper error response and tests