Giter Site home page Giter Site logo

Comments (5)

Gerzer avatar Gerzer commented on June 8, 2024

What’s your specific question? Do you have a code snippet that illustrates your issue?

from moya.

yongbeomkwak avatar yongbeomkwak commented on June 8, 2024

@Gerzer Hello!
This is where the error occurred.

as you see i tried to convert error to MoyaError but it doesn't work

guard let errorCode = (error as? MoyaError)?.response?.statusCode else {
              // error as? MoyaError is nil
                    if let moyaError = (error as? MoyaError), moyaError.errorCode == 6 {
              
                        return Single.error(api.errorMap[1009] ?? error)
                    }
                    
    return Single.error(error)
}
스크린샷 2023-11-15 오전 9 03 00

from moya.

Gerzer avatar Gerzer commented on June 8, 2024

Swift doesn’t (yet) have typed errors, so the compiler can’t guarantee that all errors that a Moya function might throw will indeed be MoyaError instances. Your code should be able to handle all errors, whether or not they’re MoyaError instances.

from moya.

yongbeomkwak avatar yongbeomkwak commented on June 8, 2024

@Gerzer Hmm.. Then How Can i use statusCode on error ??

from moya.

Gerzer avatar Gerzer commented on June 8, 2024

@Gerzer Hmm.. Then How Can i use statusCode on error ??

You can only get the statusCode property if the error type is indeed a MoyaError instance. If it’s not a MoyaError instance, then there won’t be any statusCode property.

Example usage:

do {
    // Make a request…
} catch let moyaError as MoyaError {
    let statusCode = moyaError.respone?.statusCode
    // Do something with the status code…
} catch {
    // It’s not a Moya error, so there’s no statusCode property
}

from moya.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.