0
我正在爲API構建節點封裝器,並且在將POST
請求中的pdf文件附加到服務器時收到堆棧溢出錯誤。節點封裝:超出最大調用堆棧大小
的核心邏輯是src/lob.coffee
:
fs = require "fs"
USER_AGENT = "Lob: Node Wrapper"
API_HOST = "https://api.lob.com"
API_PATH = "/v1"
module.exports = lob = (api_key) ->
request = (method, path, data, cb) ->
request_object = {
method : method,
uri : "#{API_HOST}#{API_PATH}#{path}",
headers : {
"Accept" : "application/json",
"Connection" : "close",
"User-Agent" : USER_AGENT
},
auth : {
user : api_key,
pass : ""
}
}
if typeof data is "function"
cb = data
r = request request_object, (err, res, body) ->
body = JSON.parse(body)
if body.errors? and err is null
err = body.errors
delete body.errors
cb err, body
this
if method is "POST_FORM"
form = r.form()
Object.keys(data).forEach (_k) ->
form.append _k, data[_k]
this
objects:
createObject: (data, cb) ->
path = "/objects"
data.file = fs.createReadStream data.file.substr 1
request "POST_FORM", path , data, cb
我在test/manual.coffee
寫了這個基本的文件用於測試功能:
api_key = "test_0dc8d51e0acffcb1880e0f19c79b2f5b0cc"
lob = require('../src/lob')(api_key)
object2 =
name: "TEST"
file: "@/Users/Admin/Downloads/test.pdf"
setting_id: 100
lob.objects.createObject object2, (err, res) ->
console.log err, res
但是當我運行測試文件,我收到以下錯誤:ERROR: RangeError: Maximum call stack size exceeded
,我不確定這是什麼原因。
我有點不確定爲什麼會引起遞歸? – Anconia