λ΄ λ‘컬μμ λ€λ₯Έ λλ©μΈμΌλ‘ κ²μλ¬Ό μμ²μ 보λ΄κ³ μμ΅λλ€. (μ λ Cors λ¬Έμ λ₯Ό μ°ννκΈ° μν΄ κ°λ° λͺ¨λμμ Chromeμ μ¬μ©νκ³ μμ΅λλ€)
μ΄κ²μ λ΄ μ½λμ λλ€.
axios('https://..../signup', {
method: 'POST',
data: {
email: '[email protected]',
password: 'fdsfds',
confirmPassword: 'fdsfds'
}
}).then(function(response) {
console.log('response::', response.data);
})
.catch(function(error) {
console.log('ERROR::', error.data);
});
λ¬Έμ λ 400 (Bad Request)
μνλ§ μλ΅μΌλ‘ λ°λ λ°λ©΄ curl cli/postmanμ ν΅ν΄ λμΌν μμ²μ 보λ΄λ©΄ μνμ λ€μκ³Ό κ°μ λ³Έλ¬Έμ μ»μ μ μλ€λ κ²μ
λλ€.
[
{
"param": "email",
"msg": "Email is not valid"
},
{
"param": "password",
"msg": "Password must be at least 4 characters long"
},
{
"param": "confirmPassword",
"msg": "Passwords do not match"
}
]
κ·Έλ¬λ axiosμμλ κ·Έλ μ§ μμ΅λλ€. μ΄κ²μ Cors λ¬Έμ κ° λ μ μμ΅λλ€. get/post 쿼리λ₯Ό μ λ§λ€ μ μκΈ° λλ¬Έμ μνμ ν¨κ» λ°νλλ λ³Έλ¬Έμ μ»μ μ μλ κ² κ°μ΅λλ€.
console.log('ERROR::', error.response.data);
μ΄ μμ
μ μνν κ²μ μ κ²½μ°μ§ λ§μΈμ. μ΄ μμ
μ΄ λͺ
ννκ² λ¬ΈμνλκΈ°λ₯Ό λ°λλλ€.
@samayo λ΅λ³ν΄μ£Όμ μ κ°μ¬ν©λλ€. κ°λ¨ν XHR μμ²μ μ¬μ©νμ¬ μ€λ₯ μλ΅μ λ€μ λ°λ ν μ μλνμ§λ§, axiosλ₯Ό μ¬μ©ν λ μ€λ₯κ° λ°μν κ²½μ° μλ΅μ λ€μ κ°μ Έμ¬ μ μλ μ΄μ κ° κΆκΈνμ¬ μλ²½νκ² λ΅λ³ν΄ μ£Όμ ¨μ΅λλ€. λ¬Έμμμ λ μ½κ² μ°Ύμ μ μλ€λ λ° λμνμ΅λλ€.
res μνκ° 200μΈ κ²½μ° λΉλκΈ° λκΈ° ꡬ문μ μ¬μ©νμ¬ κ²μ μμ²μ λ³΄λΌ λ μλ΅ λ³Έλ¬Έμ λ€μ 보λ΄μ§λ§ μλ΅ μνκ° 400μ΄λ©΄ μλ΅ λ³Έλ¬Έμ 보λ΄μ§ μμ΅λλ€. async await ꡬ문μ μ¬μ©νμ¬ μ€λ₯κ° λ°μνλ λ°©λ²μ 무μμ λκΉ?
κ°μ₯ μ μ©ν λκΈ
console.log('ERROR::', error.response.data);
μ΄ μμ μ μνν κ²μ μ κ²½μ°μ§ λ§μΈμ. μ΄ μμ μ΄ λͺ ννκ² λ¬ΈμνλκΈ°λ₯Ό λ°λλλ€.