better error handling and include cross origin headers on errors.