Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

285
Vistas
how to catch a error from external library and store it in a string

I use JSON5 parse method to convert the value inserted to the input element to an object

for example inserting WWEew2" to the input element and invoking the method causes an Syntax error

I want to catch the error


SyntaxError: JSON5: invalid end of input at 1:1
    at Cu (index.min.js:1)
    at ru (index.min.js:1)
    at Object.start (index.min.js:1)
    at Object.parse (index.min.js:1)
    at Vue.displayData (index.html:45)
    at invoker (vue.js:2029)
    at HTMLButtonElement.fn._withTask.fn._withTask (vue.js:1828)

especially this part SyntaxError: JSON5: invalid end of input at 1:1

using

const errorString = JSON5.stringify(e) returns {lineNumber:1,columnNumber:1}

how can I catch the full error and store it as a string in a variable ?

unfortunately the error is not displayed fully in the code snippet example, only if you run it in the browser

new Vue({
  el: "#app",
  
 

  data() {
    return {
      myInput: "",
    };
  },

  methods: {
    displayData() {
     
      try {
        console.log(JSON5.parse(this.myInput))

      } catch (e) {
          console.log(e)

        
           const errorString = JSON5.stringify(e)

          console.log(errorString)
          // {lineNumber:1,columnNumber:1}

          

      }
      
    },
  },
  
  
  
});
<script src="https://unpkg.com/json5@^2.0.0/dist/index.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>




 <div id="app">
      <button type="button" @click="displayData">display</button>
      
      <input v-model="this.myInput" >
     
     </div>

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda