2

I am using clj-http for API calls but i am getting very generic error message.

ExceptionInfo clj-http: status 415 clj-http.client/wrap-exceptions/fn--1863 (client.clj:196) 

How can i see the full response from API?

1
  • 1
    Please add the full source code of the call to clj-http (with line numbers), esp around line 196 of client.clj Commented Feb 4, 2020 at 15:42

2 Answers 2

4

The default for clj-http is to throw exceptions on >=400 status codes. So once you see an exception, dig deeper with e.g. (pst) or how you usually deal with the exception. E.g.

(c/get "https://httpbin.org/status/400")
; Execution error (ExceptionInfo) at slingshot.support/stack-trace (support.clj:201).
; clj-http: status 400
(pst)
; ...
; clojure.lang.ExceptionInfo: clj-http: status 400
;                      body: ""
;                    cached: nil
;                  chunked?: false
;                   headers: {"Date" "Tue, 04 Feb 2020 19:37:14 GMT",
;                             "Content-Type" "text/html; charset=utf-8",
;                             "Content-Length" "0",
;                             "Connection" "close",
;                             "Server" "gunicorn/19.9.0",
;                             "Access-Control-Allow-Origin" "*",
;                             "Access-Control-Allow-Credentials" "true"}
;               http-client: #object[org.apache.http.impl.client.InternalHttpClient 0x3cc148d "org.apache.http.impl.client.InternalHttpClient@3cc148d"]
;                    length: 0
;     orig-content-encoding: nil
;          protocol-version: {:name "HTTP", :major 1, :minor 1}
;             reason-phrase: "BAD REQUEST"
;               repeatable?: false
;              request-time: 429
;                    status: 400
;                streaming?: false
;           trace-redirects: []
;                      type: :clj-http.client/unexceptional-status
; ...

If you don't want this feature, you can disable it with the option :throw-exceptions false:

(c/get "https://httpbin.org/status/400" {:throw-exceptions false})
; {:body "",
;  :cached nil,
;  :chunked? false,
;  :headers {"Access-Control-Allow-Credentials" "true",
;            "Access-Control-Allow-Origin" "*",
;            "Connection" "close",
;            "Content-Length" "0",
;            "Content-Type" "text/html; charset=utf-8",
;            "Date" "Tue, 04 Feb 2020 19:40:20 GMT",
;            "Server" "gunicorn/19.9.0"},
;  :http-client #<org.apache.http.impl.client.InternalHttpClient@27bde886>,
;  :length 0,
;  :orig-content-encoding nil,
;  :protocol-version {:major 1, :minor 1, :name "HTTP"},
;  :reason-phrase "BAD REQUEST",
;  :repeatable? false,
;  :request-time 432,
;  :status 400,
;  :streaming? false,
;  :trace-redirects []}

Or if you really want to see what is going on, you can also use :debug true to let the underlying http librarly log "everything":

(c/get "https://httpbin.org/status/400" {:debug true :throw-exceptions false})
; Request: nil
; {:user-info nil,
;  :use-header-maps-in-response? true,
;  :body-type nil,
;  :debug true,
;  :headers {"accept-encoding" "gzip, deflate"},
;  :server-port nil,
;  :url "https://httpbin.org/status/400",
;  :flatten-nested-keys (:query-params),
;  :throw-exceptions false,
;  :uri "/status/400",
;  :server-name "httpbin.org",
;  :query-string nil,
;  :body nil,
;  :scheme :https,
;  :request-method :get}
; HttpRequest:
; {:config nil,
;  :method "GET",
;  :requestLine
;  #object[org.apache.http.message.BasicRequestLine 0x648100de "GET https://httpbin.org/status/400 HTTP/1.1"],
;  :aborted false,
;  :params
;  #object[org.apache.http.params.BasicHttpParams 0x3d1319b "org.apache.http.params.BasicHttpParams@3d1319b"],
;  :protocolVersion
;  #object[org.apache.http.HttpVersion 0x34b63def "HTTP/1.1"],
;  :URI
;  #object[java.net.URI 0x51ba8929 "https://httpbin.org/status/400"],
;  :class org.apache.http.client.methods.HttpGet,
;  :allHeaders
;  [#object[org.apache.http.message.BasicHeader 0x39a8905b "Connection: close"],
;   #object[org.apache.http.message.BasicHeader 0x6d6c4775 "accept-encoding: gzip, deflate"]]}
; {:body "",
;  :cached nil,
;  :chunked? false,
; ...
Sign up to request clarification or add additional context in comments.

Comments

0

The HTTP client library appears to be reporting that the server rejected your request with HTTP status code 415. The Internet Engineering Task Force defined HTTP status code 415 in RFC 7231.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.