Hi Folks, I am using ktor http client for api call...
# javascript
s
Hi Folks, I am using ktor http client for api call in my react kotlin/js project and from backend I am gettting exception with error code 401 when I check on insomnia/postman, I wonder how do I catch this error code and exception response in code, can anyone help me out here please?
t
We have suspend
fetch
in wrappers. It will be better for bundle size :)
s
okay that’s good to know, however we are using ktor in our project, please see the sample code below, currently I am just taking the exception as dynamic type and I want to know how can I get the error code and error response in catch block? suspend fun getAccountNumbers(params: String=“”): List<String> { try { val response: HttpResponse = httpClient.get(“$_BackendServerURL_”) if (response.status == HttpStatusCode.OK) { return response.body() } } catch (e: dynamic) { console.log(“Error: “, e.message) } return _emptyList_() }
t
AFAIK When you receive
HttpResponse
error producing - your responsibility