I have a problem with the API response. We're using as backend service to register async user.
I want to check if the user are registered or not, but I don't have simply message as a response, but I need to check the headers:
x-operation:operations/e18f9239-b66b-4a81-a7cb-622a40326057 This header will tell me if I send api request to another endpoint if the user are registered with this email, or not.
In the Network section I have following Response Headers:
Access-Control-Allow-Credentials:true
Access-Control-Allow-Origin:http://localhost:8080
Content-Length:0
Date:Wed, 22 Nov 2017 17:33:20 GMT
Server:Kestrel
Vary:Origin
x-operation:operations/e18f9239-b66b-4a81-a7cb-622a40326057
x-resource:account
To my request I am using axios library (react-app)
export function signupUser({ email, password }) {
return function(dispatch) {
axios.post(`${API_URL}/sign-up`, { email, password })
.then(response => {
console.log('response', response)
// browserHistory.push('/signin');
})
.catch((error) => {
// dispatch(authError(error.data.error))
console.log('error', error)
})
}
}
The problem is to handling the response. I need to check the x-operation, but the x-operation in my response doesn't appear.
When I do my console.log(response) in .then I have headers: {} empty. Here is the console.log(response)
response
{data: "", status: 202, statusText: "Accepted", headers: {…}, config: {…}, …}
config:
{transformRequest: {…}, transformResponse: {…}, timeout: 0, xsrfCookieName: "XSRF-TOKEN", adapter: ƒ, …}
data:""
headers:{}
request:XMLHttpRequest {readyState: 4, timeout: 0, withCredentials: false, upload: XMLHttpRequestUpload, onreadystatechange: ƒ, …}
status:202
statusText:"Accepted"
How can I check the response x-operation in headers, if I don't have it in axios response, only appear in Network section?
Try taking a look at this SO post: Axios get access to response header fields
You need to make sure your server is configured to allow the client to access those headers, something like: Access-Control-Expose-Headers: x-operation
I believe.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With