From c09f1567cb664641318d77850de53de363b4401a Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Tue, 13 Apr 2010 00:54:36 -0700 Subject: [PATCH] bit.ly: check response for errors --- extra/bit/ly/ly.factor | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/extra/bit/ly/ly.factor b/extra/bit/ly/ly.factor index 32d40786f7..1dcdf97dff 100644 --- a/extra/bit/ly/ly.factor +++ b/extra/bit/ly/ly.factor @@ -14,8 +14,16 @@ SYMBOLS: login api-key ; "json" "format" set-query-param swap "longUrl" set-query-param ; +ERROR: bad-response json status ; + +: check-response ( json -- json ) + dup "status_code" swap at 200 = [ + dup "status_txt" swap at + bad-response + ] unless ; + : parse-response ( response data -- short-url ) - nip json> "data" swap at "url" swap at ; + nip json> check-response "data" swap at "url" swap at ; PRIVATE>