Got questions, comments, patches, etc.?
Contact Jason Woofenden
gitweb
/
af-coffee.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
dccb74d
)
allow any json_request to return plain text
author
Jason Woofenden
<jason@jasonwoof.com>
Mon, 11 Feb 2013 21:01:20 +0000
(16:01 -0500)
committer
Jason Woofenden
<jason@jasonwoof.com>
Mon, 11 Feb 2013 21:01:20 +0000
(16:01 -0500)
api.coffee
patch
|
blob
|
history
diff --git
a/api.coffee
b/api.coffee
index
3108f4f
..
318531f
100644
(file)
--- a/
api.coffee
+++ b/
api.coffee
@@
-135,6
+135,8
@@
request = (method, path, content_type, data, token, callback) ->
req.end()
], callback
req.end()
], callback
+# send json
+# try parsing result as json, and fall back to returning string
json_request = (method, path, data, token, callback) ->
if data?
data = JSON.stringify data
json_request = (method, path, data, token, callback) ->
if data?
data = JSON.stringify data
@@
-145,7
+147,8
@@
json_request = (method, path, data, token, callback) ->
try
callback null, JSON.parse(response)
catch error
try
callback null, JSON.parse(response)
catch error
- callback "Error: AF server returned invalid JSON for #{method} to #{path}: \"#{response}\""
+ # some api calls return plain text
+ callback null, response
json_get = (path, token, callback) ->
json_request 'GET', path, null, token, callback
json_get = (path, token, callback) ->
json_request 'GET', path, null, token, callback