Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retireve message when failure from REST API. #563

Open
CodeServant opened this issue Jan 23, 2025 · 4 comments
Open

Retireve message when failure from REST API. #563

CodeServant opened this issue Jan 23, 2025 · 4 comments

Comments

@CodeServant
Copy link

I want to get the error message that is from REST server response, but I can't do it.
I have rest call like that

val restClient = RestClient()
        val premise = restClient.call<ChangeResp, DullChangeReq>(
            url = "$url/$id",
            data = changeReq
        ) {
            method = HttpMethod.PUT
            authorize()
        }
        premise.then(onFulfilled, onRejected)

and onRejected is defined like that

onRejected = {
        failToast(
           it.message,
            "insertion failed"
        )
    }

but the it.message appears to be empty string, and in fact cause is null.
My rest response is

{"timestamp":"2025-01-23T21:02:54.082+00:00","status":400,"error":"Bad Request","message":"Edge would induce a cycle","path":"/api/workflowGraphs"}

and this json is absolutely expected by me.
Is this error or am i missing something?

@rjaros
Copy link
Owner

rjaros commented Jan 23, 2025

Hello.
I think the exception you get in the onRejected callback should be RemoteRequestException. Try something like this:

onRejected = {
    console.log((it as? RemoteRequestException).response.body)
}

@CodeServant
Copy link
Author

CodeServant commented Jan 23, 2025

there is something like this after

ReadableStream { locked: false }

this is the console output

@rjaros
Copy link
Owner

rjaros commented Jan 23, 2025

There is another Promise in the response object. You can use a code like this:

(it as? RemoteRequestException)?.response?.json()?.then { 
    console.log(it)
}

@CodeServant
Copy link
Author

ok something like this worked

(it as? RemoteRequestException)?.response?.json()?.then {
    console.log(it.asDynamic().message)
}

thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants