Fix undefined issues

TypeError: Cannot read property 'name' of undefined
TypeError: Cannot read property 'code' of undefined