Promise-based Wrapper for Simple HTTP Requests built on top of Bluebird and Request
So my code looks like this
return rp(options)
.then(response => {
let timeEntries = JSON.parse(response)['time-entries'];
return timeEntries;
})
.catch(err => console.log(err.MESSAGE));
Which is a part of a method.
I am getting this error Unhandled rejection Error: StatusCodeError: 400 - "{\"MESSAGE\":\"Invalid Parameters - 'page' must be greater or equal to 1\",\"STATUS\":\"Error\"}"
then
and catch
in the snippet is perfect. The only explanation I currently have for your unhandled rejection is that you actual code doesn’t match the snippet. Or the rejection came from a different request at another spot in your code. Could you double check?
timeout
option. For the response time you can build a wrapper around your requests.
0.3.2
of request-promise and I'm seeing some issues where the request hangs indefinitely after a POST ... so I want to go through each version's release notes and find out which one might have fixed this issue or incorporated an update of request
to fix such symptoms
import request from 'request-promise-native';
TypeError: global.XMLHttpRequest is not a constructor
multipart/form-data
request
README. Btw, all request
options work for request-promise
as well. Usually, you don’t have to set the header yourself. It’s set automatically when you e.g. use the formData
option.
curl -X POST http://localhost:8080/api/v1/upload -H “authorization:here goes token"
--header "Content-type: multipart/mixed" -F "imageFile=@TestImage.jpg”
-F "imageFile=@TestImage2.jpg" -F "applicationNumber=SL-ESA-17000322" -F "personalId=12345678A"
multipart/form-data
unfortunately : /
multipart/form-data
:415 - "{\"timestamp\":1506930784462,\"status\":415,\"error\":
\"Unsupported Media Type\",\"exception\":\"org.springframework.web.HttpMediaTypeNotSupportedException\",
\"message\":\"Content type 'multipart/form-data;boundary=--------------------------732586446978103238773917' not supported\",
\"path\":\"/api/v1/upload\"}"
const formData = {
applicationNumber,
personalId,
};
const multipart = files.map(file => ({
'content-type': 'multipart/mixed',
body: fs.createReadStream(file.path),
}));
return rest.post({
postambleCRLF: true,
uri: Configuration.getIdentificationServiceUrl() + '/api/v1/upload',
headers: {
'Content-type': 'multipart/mixed',
'Authorization': token,
},
multipart,
qs: formData,
});