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

Is there any possibility to extract JSON response data when performing a DownloadRequest? #2332

Open
aaskrv opened this issue Dec 4, 2023 · 0 comments
Labels

Comments

@aaskrv
Copy link

aaskrv commented Dec 4, 2023

Hello,

I am downloading a PDF file from a specific URL using .downloadParameters task and everything works fine, PDF is displayed properly. The problem occurs when I receive an error with a JSON in response as I cannot parse and extract data from it to display the received error message.

Example Response Body that the server sends:

{
  "error" : {
    "code" : "error_code",
    "message" : "error message",
    "title" : "error title",
    "type" : "error type"
  },
  "tracing" : "error tracing",
  "status" : "error"
}

At the start, before I found the reason, this response did not even display in the Moya NetworkLogger logs and I started to investigate why. As I found out further, it was because there was no response data extracted for the DownloadRequest type requests, and response data is available only for DataRequest and DataStreamRequest types.

extension DownloadRequest: Requestable {
    internal func response(callbackQueue: DispatchQueue?, completionHandler: @escaping RequestableCompletion) -> Self {
        if let callbackQueue = callbackQueue {
            return response(queue: callbackQueue) { handler  in
                completionHandler(handler.response, handler.request, **nil**, handler.error)
            }
        } else {
            return response { handler  in
                completionHandler(handler.response, handler.request, **nil**, handler.error)
            }
        }
    }
}

So, the question is: Is there any possible solution to extract response data to display the error message, while performing a file download request?

p.s.: Moya version I am using is 15.0.0

@peril-moya peril-moya bot added the question label Dec 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant