I'm using the axios Node library within an AWS lambda to send API requests. This works fine for many of the APIs, but for https://developer.box.com/en/reference/post-files-upload-sessions/ it throws this error object:
{
"message": "Request failed with status code 400",
"name": "Error",
"stack": "Error: Request failed with status code 400\n at createError (/var/task/node_modules/axios/lib/core/createError.js:16:15)\n at settle (/var/task/node_modules/axios/lib/core/settle.js:17:12)\n at IncomingMessage.handleStreamEnd (/var/task/node_modules/axios/lib/adapters/http.js:237:11)\n at IncomingMessage.emit (events.js:203:15)\n at IncomingMessage.EventEmitter.emit (domain.js:448:20)\n at endReadableNT (_stream_readable.js:1143:12)\n at process._tickCallback (internal/process/next_tick.js:63:19)",
"config": {
"url": "https://upload.box.com/api/2.0/files/upload_sessions",
"method": "post",
"data": "{\"folder_id\":\"notTheRealId\",\"file_size\":16787785,\"file_name\":\"notTheRealFilename.mp4\"}",
"headers": {
"Accept": "application/json, text/plain, */*",
"Content-Type": "application/json",
"Authorization": "Bearer notTheRealAccessToken",
"User-Agent": "axios/0.19.0",
"Content-Length": 129
},
"transformRequest": "
null
],
"transformResponse": "
null
],
"timeout": 0,
"xsrfCookieName": "XSRF-TOKEN",
"xsrfHeaderName": "X-XSRF-TOKEN",
"maxContentLength": -1
}
}
This object doesn't conform to the description at https://developer.box.com/en/reference/resources/client-error/ In particular, there is no "code" property showing one of the explanatory values listed at https://developer.box.com/en/reference/post-files-upload-sessions/#response--400--application/json
I suspect that the API doesn't like that file_size is under 50M. I'm hesitant to structure my client around a magic number like that (by calling https://developer.box.com/en/reference/post-files-content/ for smaller files but this api for larger ones) and would prefer that the choice be driven by error codes.