Sha256: 76de1dc1e8061e12a42e9bbb5e0d3826b140b7ae643ee48ff90ab341fe2164c0

Contents?: true

Size: 681 Bytes

Versions: 4

Compression:

Stored size: 681 Bytes

Contents

import ApplicationController from './application_controller'

import ErrorModal from '../core/error_modal'

export default class extends ApplicationController {
  connect () {
    this.element.addEventListener('turbo:before-fetch-response', this.handleFormResponse)
  }

  disconnect () {
    this.element.removeEventListener('turbo:before-fetch-response', this.handleFormResponse)
  }

  handleFormResponse (e) {
    const response = e.detail.fetchResponse.response

    if (response.status >= 500) {
      e.preventDefault()

      const title = `${response.status} (${response.statusText})`
      response.text().then(content => ErrorModal.show({ title, content }))
    }
  }
}

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
trestle-0.10.1 frontend/js/controllers/form_error_controller.js
trestle-0.10.0 frontend/js/controllers/form_error_controller.js
trestle-0.10.0.pre2 frontend/js/controllers/form_error_controller.js
trestle-0.10.0.pre frontend/js/controllers/form_error_controller.js