Better handling of errors in cors proxy + little cors proxy refactoring