Skip to content
This repository has been archived by the owner on Jan 5, 2024. It is now read-only.

[fix] App randomly crash after entering Movie Detail #31

Closed
ChoiysApple opened this issue Sep 7, 2023 · 4 comments · Fixed by #44 or #48
Closed

[fix] App randomly crash after entering Movie Detail #31

ChoiysApple opened this issue Sep 7, 2023 · 4 comments · Fixed by #44 or #48
Assignees
Labels
🚑 Critical Critical Issue 🐛 bug Something isn't working
Milestone

Comments

@ChoiysApple
Copy link
Owner

ChoiysApple commented Sep 7, 2023

Cause

App randomly crashed because of error while decoding MovieDetail model

Solution

@ChoiysApple ChoiysApple added 🐛 bug Something isn't working 🚑 Critical Critical Issue labels Sep 7, 2023
@ChoiysApple ChoiysApple added this to the v0.0.1 milestone Sep 7, 2023
@ChoiysApple ChoiysApple changed the title [fix] App randomly crash after entering Movie Detail [fix] App randomly crash after entering Movie Detail Sep 7, 2023
@ChoiysApple ChoiysApple pinned this issue Sep 7, 2023
@ChoiysApple ChoiysApple unpinned this issue Sep 7, 2023
@ChoiysApple ChoiysApple self-assigned this Oct 5, 2023
@ChoiysApple ChoiysApple linked a pull request Oct 6, 2023 that will close this issue
@ChoiysApple
Copy link
Owner Author

ChoiysApple commented Oct 6, 2023

App crash not happened after #19 issue is solved.
Code improvement will continue on issue #43

@ChoiysApple
Copy link
Owner Author

Issue found for movieId: 401068

{
  "adult": false,
  "backdrop_path": null,
  "belongs_to_collection": null,
  "budget": 0,
  "genres": [
    {
      "id": 35,
      "name": "Comedy"
    }
  ],
  "homepage": "",
  "id": 401068,
  "imdb_id": "tt1243457",
  "original_language": "en",
  "original_title": "Dave Attell - HBO Comedy Half-Hour",
  "overview": "Dave Attell brings us more of his good old stand-up jokes about cow sex and trash trucks in this half-hour comedy special.",
  "popularity": 1.164,
  "poster_path": null,
  "production_companies": [
    {
      "id": 3268,
      "logo_path": "/tuomPhY2UtuPTqqFnKMVHvSb724.png",
      "name": "HBO",
      "origin_country": "US"
    },
    {
      "id": 8803,
      "logo_path": null,
      "name": "Production Partners",
      "origin_country": ""
    }
  ],
  "production_countries": [
    {
      "iso_3166_1": "US",
      "name": "United States of America"
    }
  ],
  "release_date": "1996-08-16",
  "revenue": 0,
  "runtime": 27,
  "spoken_languages": [
    {
      "english_name": "English",
      "iso_639_1": "en",
      "name": "English"
    }
  ],
  "status": "Released",
  "tagline": "",
  "title": "Dave Attell - HBO Comedy Half-Hour",
  "video": false,
  "vote_average": 1,
  "vote_count": 1
}

@ChoiysApple
Copy link
Owner Author

Crash cases

Id Null items
401068 backdrop_path, belongs_to_collection
438836 backdrop_path, belongs_to_collection
377532 imdb_id

@ChoiysApple ChoiysApple linked a pull request Oct 9, 2023 that will close this issue
@ChoiysApple
Copy link
Owner Author

Cause

MovieData Model is made for decoding response of Movie Detail request. But It cannot handle if there's null response.

Solution

1. Change all of MovieData's property into Optional (Cannot find proper reference for MovieDB)

// MARK: - MovieDetail
struct MovieDetail: Codable {
    let adult: Bool?
    let backdropPath: String?
    let belongsToCollection: BelongsToCollection?
    let budget: Int?
...
  1. Change data setting method from DetailViewController to handle Optional values and change some UI when there's empty data (Hiding backdropImage)
// Binding Helper
private func applyMovieDetailData(data: MovieDetail) {
    
    if let backdropPath = data.backdropPath {
        self.backDropImage.setImage(path: APIService.configureUrlString(imagePath: data.backdropPath))
    } else {
       // Make some space for backButton when there's no Backdrop image
        self.backDropImage.isHidden = true
        self.backDropImage.snp.remakeConstraints { make in
            make.top.left.right.equalToSuperview()
            make.width.equalToSuperview()
            make.bottom.equalTo(backButton.snp.bottom)
        }
    }
    
    self.titleLabel.text = data.title
    self.taglineLabel.text = data.tagline
    
    if let runtime = data.runtime {
        self.runtimeIconLabel.label.text = "\(runtime) min"
    } else {
        self.runtimeIconLabel.isHidden = true
    }
    
    if let voteAverage = data.voteAverage {
        self.ratingIconLabel.label.text = String(voteAverage)
    } else {
        self.ratingIconLabel.isHidden = true
    }
    
    self.overview.contentLabel.text = data.overview
    self.dateGenre.leftDescription.contentLabel.text = data.releaseDate?.replacingOccurrences(of: "-", with: ".")
    
    let genres = data.genres?.compactMap { $0.name }.joined(separator: ", ")
    self.dateGenre.rightDescription.contentLabel.text = genres
}

This issue is fixed, but need more improvement with refactoring

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🚑 Critical Critical Issue 🐛 bug Something isn't working
Projects
No open projects
Status: Deployed
1 participant