I simplified the issue to a basic POST request.
On the client side, when I click on the button to add a Person, I get a 500 HTTP code error:
POST http://127.0.0.1:3333/persons 500 (Internal Server Error)
app.js:518 Error: Request failed with status code 500
at createError (commons.app.js:793)
at settle (commons.app.js:956)
at XMLHttpRequest.handleLoad (commons.app.js:326)
AdonisJs 4.1.0
npm: 6.9.0
Node.js: 11.8.0
On the client side (Nuxt.js) , I have this function:
async saveUsers() {
let person = new FormData()
person.append('name', 'Python')
await this.$axios.$post('http://127.0.0.1:3333/persons', person)
}
On the server side, I have this on the controller:
async store({ request, response }) {
const data = request.post()
console.log(data) // Ok
const person = new Person()
person.name = data.name // Change to person.name = 'Virk' , issue remains
console.log(person.name) // Ok
await person.save() / If I remove this line and async error disappears
}
Nuxt.js on the front end: go the client folder and install the dependencies via: yarn install. Then run the server: yarn run dev
On the server side, it is AdonisJs. You know how to use it.
Link to repo here.
@begueradj i think you dont need to write the full route request at axios await this.$axios.$post('http://127.0.0.1:3333/persons', person) just post at:
await this.$axios.$post('/persons', person)
@begueradj sorry i hadn't a time to look at your repo to test it.
@annymosse What you said is true when we set the baseURL key in nuxt.config.js. I did not use it here by purpose because baseURL does not work all the time, I experienced this: in the same project, some requests recognize it, others not.
Thank you for the feedback
Hey @begueradj! 馃憢
Could you please give us the error message you have with the error 500?
Also as @annymosse said, you definitely need to use the relative URL and not the full one.
If it doesn't work it's an error on your configuration.
It is optional to set the baseURL key for axios. Anyway the request reaches the server, the problem is not the client as I commented in the code above: it is await person.save() which causes an issue.
I shared the full error message (which does not say much)
Thank you
You shared the error message of your frontend, not the server one. 馃槃
@RomainLanz you need to take a look at his issuse ; @begueradj has shared his bug report,and his problem coming out from the server side at the person controller ,exact at await person.save() because everything is work well until the transpiler reach await person.save() look like there is a bug at the lucid package,or something else the client as he said in his post issuse :
...
On the server side, I have this on the controller:async store({ request, response }) { const data = request.post() console.log(data) // Ok const person = new Person() person.name = data.name // Change to person.name = 'Virk' , issue remains console.log(person.name) // Ok await person.save() / If I remove this line and async error disappears }....
Link to repo here.
Hey @annymosse! 馃憢
I asked to have the error from Adonis, I cannot do much without having it.
Je vois que tu n'as pas oubli茅 ce probl猫nme technique, ceci dit merci pour ta curiosit茅 et ton feedback @annymosse
I closed this because it was not a bug, I do not remember how I solved it but I think I was trying to insert a row into the database and the primary key was duplicate. So later I protected the code with a tryblock.
@RomainLanz IMHO, one of the issues with AdonisJs is that often it does not tell you about the culprit line of code.
This was not a bug, but a naive mistake (duplicate primary key, if I remember), otherwise I would not close this. In general, AdonisJs is reliable and I am switching my applicationsto it.
@RomainLanz yup i thought you mean the reason behind that bug :grin: ; @begueradj i suggest to use try{}catch() to handle your unknown results or problems.
@begueradj bonne chance avec vos projets surtout avec ces jours en France.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Most helpful comment
Hey @annymosse! 馃憢
I asked to have the error from Adonis, I cannot do much without having it.