Skip to content

Commit

Permalink
Add requestState to both entities
Browse files Browse the repository at this point in the history
  • Loading branch information
kean committed Oct 4, 2021
1 parent 62d854e commit 09f876c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions Pulse/Sources/PulseCore/LoggerStore+MOM.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ public extension LoggerStore {
let duration = NSAttributeDescription(name: "duration", type: .doubleAttributeType)
let contentType = NSAttributeDescription(name: "contentType", type: .stringAttributeType)
let isCompleted = NSAttributeDescription(name: "isCompleted", type: .booleanAttributeType)
let state = NSAttributeDescription(name: "state", type: .integer16AttributeType)
let requestState = NSAttributeDescription(name: "requestState", type: .integer16AttributeType)
let requestBodyKey = NSAttributeDescription(name: "requestBodyKey", type: .stringAttributeType)
let responseBodyKey = NSAttributeDescription(name: "responseBodyKey", type: .stringAttributeType)
let details = NSRelationshipDescription.make(name: "details", type: .oneToOne(), entity: requestDetails)
let message = NSRelationshipDescription.make(name: "message", type: .oneToOne(), entity: message)
request.properties = [createdAt, session, url, host, httpMethod, errorDomain, errorCode, statusCode, duration, contentType, requestBodyKey, responseBodyKey, details, message, isCompleted, state]
request.properties = [createdAt, session, url, host, httpMethod, errorDomain, errorCode, statusCode, duration, contentType, requestBodyKey, responseBodyKey, details, message, isCompleted, requestState]
}

model.entities = [message, metadata, request, requestDetails]
Expand Down Expand Up @@ -155,13 +155,13 @@ public final class LoggerNetworkRequestEntity: NSManagedObject {
@NSManaged public var duration: Double
@NSManaged public var contentType: String?
@NSManaged public var isCompleted: Bool
@NSManaged public var state: Int16
@NSManaged public var requestState: Int16

public enum State: Int16 {
// 0 reserved for undefined
case pending = 1 // not used yet
case success
case failure
case success = 2
case failure = 3
}

// Details
Expand Down
4 changes: 2 additions & 2 deletions Pulse/Sources/PulseCore/LoggerStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ extension LoggerStore {
let messageEntity = self.makeMessageEntity(with: messageObject)
let requestEntity = self.makeRequest(summary, createdAt: summary.createdAt)
messageEntity.request = requestEntity
messageEntity.requestState = requestEntity.state
messageEntity.requestState = requestEntity.requestState
requestEntity.message = messageEntity
}

Expand Down Expand Up @@ -352,7 +352,7 @@ extension LoggerStore {
entity.contentType = summary.response?.headers["Content-Type"]
entity.isCompleted = true
let isFailure = errorCode != 0 || (statusCode != 0 && !(200..<400).contains(statusCode))
entity.state = (isFailure ? LoggerNetworkRequestEntity.State.failure : .success).rawValue
entity.requestState = (isFailure ? LoggerNetworkRequestEntity.State.failure : .success).rawValue
// Details
entity.details = makeRequestDetails(summary)
if case let .directory(store) = document {
Expand Down

0 comments on commit 09f876c

Please sign in to comment.