Coder Social home page Coder Social logo

Comments (7)

joaomvfsantos avatar joaomvfsantos commented on May 23, 2024 1

@pcantrell I'm having the same issue, on my side I can't do anything about the server so I was looking to do something like the work around you suggested. Seems the syntax is for a deprecated version of Siesta. I'm adding the ChangeEmptyResponseContentType transformer like the below, but still have Siesta returning me the "Cannot parse server response" error.

configure(configurer: { (configuration) in
     configuration.pipeline[.rawData].add(ChangeEmptyResponseContentType())
     configuration.pipeline[.rawData].cacheUsing(PersistentCache<Data>())
     configuration.headers["Authorization"] = self.headers["Authorization"]
})

PersistentCache is my implementation of EntityCache I'm using and the Authorization header, well, it's just an Authorization header. Any ideas?

Thank you!

from siesta.

pcantrell avatar pcantrell commented on May 23, 2024

This should be fixed in the next beta release.

If you’re brave and foolhardy, try master and see if it’s fixed for you already.

from siesta.

pcantrell avatar pcantrell commented on May 23, 2024

Wait, apologies, I mistook this for another bug. I should have looked at your log more carefully before answering.

It looks like your server is sending Content-Type: application/json even though the response is empty. That’s causing Siesta to attempt to parse the response as JSON, which gives the “no value” error you’re seeing.

A 204 should not give a content-type header, since there is no content. Is that something you have control over?

from siesta.

shaneneuerburg avatar shaneneuerburg commented on May 23, 2024

The library used for the scaffolding of the API is Restler (PHP), which apparently doesn't abide by that rule. I'll post an issue with them and see if I can override that for now.

from siesta.

pcantrell avatar pcantrell commented on May 23, 2024

If they're unable to change it, feel free to reopen this issue, and we'll either decide to make Siesta handle it as a special case or get you a configuration workaround.

from siesta.

pcantrell avatar pcantrell commented on May 23, 2024

Seeing that you’ve only got a workaround from the Restler side, I’ll give you a Siesta-side workaround to choose from as well.

You can make a response transformer that assigns a made-up content-type to empty responses to suppress further processing:

struct ChangeEmptyResponseContentType: ResponseTransformer
    {
    func process(response: Siesta.Response) -> Siesta.Response
        {
        switch(response)
            {
            case .Success(var entity):
                if let data = entity.content as? NSData where data.length == 0
                    { entity = Entity(content: NSData(), contentType: "unknown/empty") }
                return .Success(entity)

            case .Failure:
                return response
            }
        }
    }

…and then, when configuring your service, make it the first transformer in the pipeline:

configure
    {
    $0.config.responseTransformers.add(
        ChangeEmptyResponseContentType(),
        first: true)
    }

That’s just a hack, but it does give you another option if the Restler patch doesn’t suit.

from siesta.

shaneneuerburg avatar shaneneuerburg commented on May 23, 2024

Great, thank you!

from siesta.

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.