Comments (5)
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.
What does your ErrorHandler.handleSpineError
do?
Could you elaborate it?
thanks in advance.
from spine.
Anybody please?
from spine.
@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.
@markst
Will check it and let you know.
Thanks.
from spine.
Related Issues (20)
- How to convert Resource to JSON?
- Error: Expressions are not allowed at the top level HOT 1
- How to use ToOneRelationship() and serializeAs() on the same attribute? HOT 7
- POST one type of resource, receive a different type in response HOT 2
- NetworkClient request to return the URLSessionTask HOT 1
- Querying nested relationships doesn't use relationships link URL
- is it possible "2 level sortings"? HOT 1
- Including attributes into relationship object HOT 4
- Polymorphic relationship HOT 1
- Serializing Resources for storage in UserDefaults HOT 4
- Array of custom type in resource definition
- How can I get relation objects from parent Resource?
- URL Formatting
- Retrieving more than one relationship HOT 3
- Couldn’t fetch resources using spine.fine() with Query
- How to ignore empty/nil relationships when updating Resource?
- Not maintained anymore HOT 7
- JSONAPIDocument public HOT 1
- New Xcode install
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from spine.