2020年12月21日星期一

Getting error 422 when trying to apply axios.get method

I got Error 422 when trying to apply a GET method with Axios. Apparently, the input JSON content wrong information. I need to let all the parameters as null or with some value by default to be able to do the query to the database with any combination of parameters. When testing the API, everything is OK.

The methods:

import axios from 'axios'  export default {      name: 'UserConsulta',      data: function(){          return {              username: null,              movement: null,              movement_type: null,              movement_category: null,              dateFrom: null,              dateUntil: null,              amountFrom: null,              amountUntil: null          }      },      methods:{          getMovement: function(){              var self = this              let consulta_in = {                  username: this.username,                  movement: this.movement,                  movement_type: this.movement_type,                  movement_category: this.movement_category,                  dateFrom: this.dateFrom,                  dateUntil: this.dateUntil,                  amountFrom: this.amountFrom,                  amountUntil: this.amountUntil              }              axios.get("http://127.0.0.1:8000/user/consulta/")              .then((result) => {                  self.query = result.data.query              })              .catch((error) => {                  if (error.response.status == "400")                      alert("ERROR 400: La búsqueda no arrojó resutlados");              })          },          created: function(){              this.username = this.$route.params.username          }      }  }  

The api.get using FastAPI:

@api.get("/user/consulta/")  async def get_consulta(consulta_in: ConsultaIn):        consulta_in_db = get_movement(consulta_in)        if consulta_in_db == None:          raise HTTPException(status_code=404, detail="El usuario no existe")      elif consulta_in_db == []:          raise HTTPException(status_code=404, detail="Su búsqueda no arrojó resultados")        return  consulta_in_db  
https://stackoverflow.com/questions/65401989/getting-error-422-when-trying-to-apply-axios-get-method December 22, 2020 at 09:03AM

没有评论:

发表评论