[Konstrukt] Implementing 422: How do I maintain context?

1 view
Skip to first unread message

Thomas Allen

unread,
Apr 28, 2010, 11:56:32 AM4/28/10
to Konstrukt
I am trying to implement 422 because Konstrukt doesn't seem to (Ruby
on Rails' ActiveResource expects errors on save to return an errors
object with this code). My difficulty is in getting my errors into the
error-handling component: In the code below, the $errors attribute is
not found in UnprocessableEntity's dispatch method with "Undefined
property: k_HttpRequest::$errors."

What am I doing wrong?

In the component that generates the errors:

function postXml() {
// Omitted $record-building logic
try {
$record->save();
} catch(Doctrine_Validator_Exception $e) {
// Omitted $error-building logic
$this->xml->serialize($errors);
$this->context->errors = $this->xml->getSerializedData();
throw new Unprocessable();
}
}

The MetaResponse:

class Unprocessable extends k_MetaResponse {
function componentName() {
return 'Unprocessable_Entity';
}
}

And finally, the component that is trying to implement 422 (it does
set the error code successfully):

class Unprocessable_Entity extends App {
function dispatch() {
$response = new k_XmlResponse($this->context->errors);
$response->setStatus(422);
return $response;
}
}

So does anybody have an idea as to why I cannot access the errors
attribute here, and what I might be able to do to share this data,
short of using globals (my unfortunate stopgap solution)?

Thomas

--
You received this message because you are subscribed to the Google Groups "Konstrukt" group.
To post to this group, send email to kons...@googlegroups.com.
To unsubscribe from this group, send email to konstrukt+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/konstrukt?hl=en.

troels knak-nielsen

unread,
May 2, 2010, 3:59:49 PM5/2/10
to kons...@googlegroups.com
In this case, I wouldn't use a meta response. Just create the response
and return it. Eg.:

function postXml() {
// Omitted $record-building logic
try {
$record->save();
} catch(Doctrine_Validator_Exception $e) {
// Omitted $error-building logic
$this->xml->serialize($errors);
$response = new k_XmlResponse($this->xml->getSerializedData());
$response->setStatus(422);
return $response;
}
}

The point of MetaResponse' are to create an abstraction between your
application and the response - Something that you don't want here,
because the response is actually contextual.

--
troels

Thomas Allen

unread,
May 11, 2010, 4:33:26 PM5/11/10
to Konstrukt
On May 2, 3:59 pm, troels knak-nielsen <troel...@gmail.com> wrote:
>       $response = new k_XmlResponse($this->xml->getSerializedData());
>       $response->setStatus(422);
>       return $response;

Thanks, that makes sense. I didn't think to create a new response
instance.

Thomas
Reply all
Reply to author
Forward
0 new messages