pointfreeco / swift-url-routing

A bidirectional router with more type safety and less fuss.
https://swiftpackageindex.com/pointfreeco/swift-url-routing/main/documentation/urlrouting
MIT License
352 stars 30 forks source link

Decoding issue #45

Closed saroar closed 2 years ago

saroar commented 2 years ago

My playground code which dont have any issue playground code here https://gist.github.com/saroar/a1bab728f4292c54cb76085a633c6a3c my client iOS app dont send any request to server becz its not decoding my query https://github.com/AddaMeSPB/AddaMeIOS/blob/siteRouter/AddameSPM/Sources/EventView/EventsReducer.swift#L112 error coming from decoding from this https://github.com/pointfreeco/swift-url-routing/blob/main/Sources/URLRouting/Client/Client.swift#L53

HTTPRequest.HRError(
        description: "fetch events get error",
        reason: URLRoutingDecodingError(
          bytes: Data(35 bytes),
          response: NSHTTPURLResponse(),
          underlyingError: DecodingError.dataCorrupted(
            DecodingError.Context(
              codingPath: [],
              debugDescription: "The given data was not valid JSON.",
              underlyingError: NSError(
                domain: "NSCocoaErrorDomain",
                code: 3840,
                userInfo: [
                  "NSDebugDescription": "Invalid value around line 1, column 0.",
                  "NSJSONSerializationErrorIndex": 0
                ]
              )
            )
          )
        )
      )
saroar commented 2 years ago
Screenshot 2022-08-30 at 08 45 59
saroar commented 2 years ago

I have test it on my api server working good only issue was from iOS client https://github.com/AddaMeSPB/EventEngine/blob/master/Tests/AppTests/Event/EventsRoutingTests.swift#L14

saroar commented 2 years ago

I am getting this decoding issue lots of time I am not sure its have issue or dont get proper error message becz

  case let .imageUploadResponse(.success(imageURLString)):
        guard let user: UserOutput = KeychainService.loadCodable(for: .user) else {
          return .none
        }

      let attachment = AttachmentInOutPut(type: .image, userId: user.id, imageUrlString: imageURLString)

      return .task {
          do {

              let attacment = try await environment.attachmentClient.updateUserImageURL(attachment)
              return ProfileAction.attacmentResponse(.success(attacment))
          } catch {
              return ProfileAction.attacmentResponse(
                .failure(
                    HTTPRequest.HRError.custom("cant upload attachment", error)
                )
              )
          }
      }

from clicnt I am trying to send like this I am 100% sure i dont have decoding issue at all

here my client https://github.com/AddaMeSPB/AddaMeIOS/blob/siteRouter/AddameSPM/Sources/AttachmentClient/AttachmentClient.swift here my live implement https://github.com/AddaMeSPB/AddaMeIOS/blob/siteRouter/AddameSPM/Sources/AttachmentClientLive/Live.swift#L91

my reducer https://github.com/AddaMeSPB/AddaMeIOS/blob/siteRouter/AddameSPM/Sources/ProfileView/ProfileReducer.swift#L50

and form this https://github.com/AddaMeSPB/AddaMeIOS/blob/siteRouter/AddameSPM/Sources/AttachmentClientLive/Live.swift#L84 I am getting sometimes error too

HRError
  - description : "Failed to load the request: Optional(HTTPClientError.deadlineExceeded)"
  ▿ reason : Optional<Error>
    ▿ some : HTTPClientError.deadlineExceeded
      - code : AsyncHTTPClient.HTTPClientError.(unknown context at $104271798).Code.deadlineExceeded

testing from server side no issue https://github.com/AddaMeSPB/AddaMeAuth/blob/siteRouter/Tests/AppTests/AttachmentTests.swift#L26

stephencelis commented 2 years ago

@saroar It looks like the server is sending back a "deadline exceeded" error, which is why decoding is failing.

You can see the definition here:

https://github.com/swift-server/async-http-client/blob/7f998f5118de081fa2034833ce95bb5925dc6459/Sources/AsyncHTTPClient/HTTPClient.swift#L1181-L1182

I'm not familiar with this error or how to work around it, but I don't think it's a bug with our library. Can you ask someone in a community more familiar with the HTTPClient library, and whatever server code you are using to serve up that response? They may be able to help you debug. If it turns out to be an issue with our library we'd be happy to address! We just need a reproduction.

Since this doesn't appear to be a bug in our library, I'm going to close it. But if you do believe there's a bug in our library, please file a new issue with a reproduction for us to work with and instructions on how to reproduce. Without steps to reproduce, we really don't have much of an ability to try to fix.