Giter Club home page Giter Club logo

Comments (5)

markst avatar markst commented on August 21, 2024

Hey @sachin-sat, here's an example which might help you out:

}.onFailure { [unowned sender, weak self] (spineError) in
    
    sender.isEnabled = true
    sender.hideLoadingView()

    ErrorHandler.handleSpineError(error: spineError)
        
    switch spineError {
    case .serverError(_, let apiErrors):
        DispatchQueue.main.async {

            if let handled = self?.fittingInformationViewController?.fittingInformationView.handleAPIError(apiErrors: apiErrors!),
                handled == true {
                
                // Scroll user to first index:
                if self?.pageController?.selectedIndex != 0 {
                    self?.pageController?.selectedIndex = 0
                }
            }
        }
        break
    default: break
    }

from spine.

sachin-sat avatar sachin-sat commented on August 21, 2024

What does your ErrorHandler.handleSpineError do?
Could you elaborate it?
thanks in advance.

@markst

from spine.

sachin-sat avatar sachin-sat commented on August 21, 2024

Anybody please?

from spine.

markst avatar markst commented on August 21, 2024

@sachin-sat ErrorHandler is my own class written for convenience, here's some example:

import Spine

class ErrorHandler {
    
    class func handleSpineError(error: SpineError) {
        
        var message: String?
        var properties: [NSObject : AnyObject]?
        
        switch error {
        case .serverError(let statusCode, let apiErrors):
            if let firstError = apiErrors?.first {
                message = firstError.detail
                
                if statusCode == 401 {
                    /*
                    Session.clearCurrent()
                    NotificationCenter.default.post(name: Constants.Application.Notifications.HTTP401ResponseNotification.name,
                                                    object: nil)
                     */
                }
            } else {
                message = "Unknown server error"
            }
        case .networkError(let networkError):
            message = networkError.localizedDescription
            properties = networkError.userInfo as [NSObject : AnyObject]?
        case .serializerError(let serializerError):
            
            switch serializerError {
            case .invalidDocumentStructure:
                message = "The given JSON is not a dictionary (hash)."
            case .topLevelEntryMissing:
                message = "None of 'data', 'errors', or 'meta' is present in the top level."
            case .topLevelDataAndErrorsCoexist:
                message = "Top level 'data' and 'errors' coexist in the same document."
            case .invalidResourceStructure:
                    message = "The given JSON is not a dictionary (hash)."
            case .resourceTypeMissing:
                message = "'Type' field is missing from resource JSON."
            case .resourceTypeUnregistered(let resourceType):
                message = "The resource type: \(resourceType) has not been registered to Spine."
            case .resourceIDMissing:
                message = "'ID' field is missing from resource JSON."
            /// Error occurred in NSJSONSerialization
            case .jsonSerializationError(let error):
                message = error.localizedDescription
            default:
            message = "Unknown Server Error" // Treating all serializer errors as internal errors until server correctly returns JSON:API formatted errors.
            }
        case .nextPageNotAvailable:
            message = "Next Page Not Available"
        case .previousPageNotAvailable:
            message = "Previous Page Not Available"
        case .unknownError:
            message = "Unknown Error"
        case .resourceNotFound:
            message = "Resource Not Found"
        default:
            print("Expected error to be be .ServerError")
            message = "Unhandled Error"
        }

        ErrorHandler.showErrorView(with: message!)
        
        #if ADHOC
            NSLog("ErrorHandler.handleSpineError with message: \(message)")
        #endif
        /*
        DefaultTracker.trackError(errorMessage: message, properties: properties)
         */
    }

from spine.

sachin-sat avatar sachin-sat commented on August 21, 2024

@markst
Will check it and let you know.
Thanks.

from spine.

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.