Detalierte Fehlermeldung für die API-Verbindung
This commit is contained in:
parent
c8350b3c19
commit
def6cac592
@ -1,4 +1,5 @@
|
|||||||
import axios from 'axios'
|
// VERSION 1:
|
||||||
|
/*import axios from 'axios'
|
||||||
|
|
||||||
const baseUrl = 'http://localhost:8001/api/v1/book/registration/search/isbn/' // Passe die URL an
|
const baseUrl = 'http://localhost:8001/api/v1/book/registration/search/isbn/' // Passe die URL an
|
||||||
|
|
||||||
@ -16,8 +17,47 @@ export default {
|
|||||||
// Zeige dem Benutzer eine informative Fehlermeldung an
|
// Zeige dem Benutzer eine informative Fehlermeldung an
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
}*/
|
||||||
|
|
||||||
|
// ********************************
|
||||||
|
// VERSION 2:
|
||||||
|
import axios from 'axios'
|
||||||
|
|
||||||
|
const baseUrl = 'http://localhost:8001/api/v1/book/registration/search/isbn/'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
async getBookByIsbn(isbn) {
|
||||||
|
try {
|
||||||
|
const response = await axios.get(`${baseUrl}${isbn}`, {
|
||||||
|
timeout: 5000, // Adjust timeout as needed
|
||||||
|
})
|
||||||
|
|
||||||
|
return response.data
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Fehler beim Abrufen des Buches:', error)
|
||||||
|
console.error('Antwort vom Server:', error.response)
|
||||||
|
|
||||||
|
// Detailliertere Fehlerbehandlung basierend auf dem Fehlertyp
|
||||||
|
if (error.response && error.response.status === 404) {
|
||||||
|
console.error('Buch nicht gefunden')
|
||||||
|
} else if (error.code === 'ECONNABORTED') {
|
||||||
|
console.error('Verbindungsabbruch')
|
||||||
|
} else if (error.response && error.response.status === 500) {
|
||||||
|
console.error('Interner Serverfehler')
|
||||||
|
} else {
|
||||||
|
console.error('Unbekannter Fehler')
|
||||||
|
}
|
||||||
|
|
||||||
|
// Zeige dem Benutzer eine benutzerfreundliche Fehlermeldung an
|
||||||
|
throw new Error('Ein Fehler ist beim Abrufen des Buchs aufgetreten.')
|
||||||
|
}
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// ********************************
|
||||||
|
// VERSION 3:
|
||||||
/*const axios = require('axios')
|
/*const axios = require('axios')
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user