(attrs, options)
| 210 | } |
| 211 | |
| 212 | save (attrs, options) { |
| 213 | if (options == null) { options = {} } |
| 214 | const originalOptions = _.cloneDeep(options) |
| 215 | if (options.headers == null) { options.headers = {} } |
| 216 | options.headers['X-Current-Path'] = (document.location != null ? document.location.pathname : undefined) != null ? (document.location != null ? document.location.pathname : undefined) : 'unknown' |
| 217 | const { |
| 218 | success, |
| 219 | } = options |
| 220 | const { |
| 221 | error, |
| 222 | } = options |
| 223 | options.success = (model, res) => { |
| 224 | this.retries = 0 |
| 225 | this.trigger('save:success', this) |
| 226 | if (success) { success(this, res) } |
| 227 | if (this._revertAttributes) { this.markToRevert() } |
| 228 | this.clearBackup() |
| 229 | CocoModel.pollAchievements() |
| 230 | options.success = (options.error = null) // So the callbacks can be garbage-collected. |
| 231 | } |
| 232 | options.error = (model, res) => { |
| 233 | let left, notyError |
| 234 | if (res.status === 0) { |
| 235 | let msg |
| 236 | if (this.retries == null) { this.retries = 0 } |
| 237 | this.retries += 1 |
| 238 | if (this.retries > 20) { |
| 239 | msg = 'Your computer or our servers appear to be offline. Please try refreshing.' |
| 240 | noty({ text: msg, layout: 'center', type: 'error', killer: true }) |
| 241 | return |
| 242 | } else { |
| 243 | msg = $.i18n.t('loading_error.connection_failure', { defaultValue: 'Connection failed.' }) |
| 244 | try { |
| 245 | noty({ text: msg, layout: 'center', type: 'error', killer: true, timeout: 3000 }) |
| 246 | } catch (error1) { |
| 247 | notyError = error1 |
| 248 | console.warn("Couldn't even show noty error for", error, 'because', notyError) |
| 249 | } |
| 250 | return _.delay(() => this.save(attrs, originalOptions), 3000) |
| 251 | } |
| 252 | } |
| 253 | if (error) { error(this, res) } |
| 254 | if (!this.notyErrors) { return } |
| 255 | const errorMessage = `Error saving ${(left = this.get('name')) != null ? left : this.type()}` |
| 256 | console.log('going to log an error message') |
| 257 | console.warn(errorMessage, res.responseJSON) |
| 258 | if (!(typeof webkit !== 'undefined' && webkit !== null ? webkit.messageHandlers : undefined)) { // Don't show these notys on iPad |
| 259 | try { |
| 260 | noty({ text: `${errorMessage}: ${res.status} ${res.statusText}\n${res.responseText}`, layout: 'topCenter', type: 'error', killer: false, timeout: 10000 }) |
| 261 | } catch (error2) { |
| 262 | notyError = error2 |
| 263 | console.warn("Couldn't even show noty error for", error, 'because', notyError) |
| 264 | } |
| 265 | } |
| 266 | options.success = (options.error = null) // So the callbacks can be garbage-collected. |
| 267 | } |
| 268 | this.trigger('save', this) |
| 269 | return super.save(attrs, options) |
no test coverage detected