Fix handling of errors from API where code is nil