PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, July 11, 2022

[FIXED] How to get error message from response body when use Alamofire.download() request

 July 11, 2022     alamofire, download, message, response, swift     No comments   

Issue

AF.download(url, parameters: params, to: destination)
  .validate(statusCode: [200])
  .response { response in
    switch response.result {
    case .success(let url):
      print("ok", url)
    case .failure(let err):
      print(err.localizedDescription)
    }
  }

When server response some error code like 4xx, 5xx, it will print "Response status code was unacceptable: xxx.", but I want the detail message in response body(server send plain text when error), I read some post that said we can retrieve response message with "response.data" but if use AF.download method, there isn't have "data" property with response object(Alamofire.AFDownloadResponse). so, is there any way to figure it out?


Solution

Alamofire's DownloadResponse contains a fileURL: URL? property which can be used to load the downloaded data from disk even when validation or other actions produce a failure result in the response.



Answered By - Jon Shier
Answer Checked By - Marilyn (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing