Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

597
Views
Svelte (Express y Axios): error http 500 en el método put

Estoy perdido. Tengo una aplicación esbelta (Backend: Express, Frontend: Axios). Tengo un MongoDB con ubicaciones. Las ubicaciones tienen una variedad de bandas. Y quiero agregar bandas a esta matriz. El backend parece funcionar bien, al menos con Postman funciona. Pero cuando trato de agregar una banda a través de la interfaz, aparece un error http 500.

Este es el código de fondo:

 app.put('/api/locations/:location', async (req, res) => { let location = req.params.location; let updatedlocation = req.body; try { await client.connect(); const database = client.db('Concerts'); const collection = database.collection('locations'); const query = { locationname: location }; const result = await collection.updateOne(query, { $set: updatedlocation }); if (result.matchedCount === 0) { let responseBody = { status: "No Location under the name " + location } res.status(404).send(responseBody); } else { res.send({ status: "Location " + location + " has been updated." }); } } catch (error) { res.status(500).send({ error: error.message }); }})

Este es el método en la interfaz:

 function addConcert() { location.concerts.push(chosenband); console.log("http://localhost:3001/api/locations/" +name); console.log(location); axios.put("http://localhost:3001/api/locations/" +name, location) .then((response) => { alert("Konzert wurde hinzugefügt"); }) .catch((error) => { alert("Nope"); console.log(error); }); }

Información: {chosenband} proviene de una selección. Esto parece funcionar también, como muestran los registros de la consola. El objeto es correcto e incluye la nueva banda:

este es el registro del navegador

Así que el objeto parece estar bien. También el put-url es correcto.

Pero siempre me sale este error 500

¡Agradecido por cualquier consejo!

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Encontré el problema. No instalé la ubicación correctamente. Primero lo instalé simplemente como

 let location = {}

, eso no funcionó. Cuando lo instalé con todos los atributos

 let location = {example:"", second:""}

funcionó. Gracias por tu ayuda

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!