Skip to content

Commit

Permalink
Include the error message in the exception object.
Browse files Browse the repository at this point in the history
  • Loading branch information
scotchi committed Nov 3, 2011
1 parent 4548cf5 commit af3c3ed
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion Ruby/QAR.cpp
Expand Up @@ -78,6 +78,7 @@ static const ID __body = rb_intern("@body");
static const ID __headers = rb_intern("@headers");
static const ID __prefix_options = rb_intern("@prefix_options");
static const ID __response = rb_intern("@response");
static const ID __message = rb_intern("@message");

/*
* Class variable symbols
Expand Down Expand Up @@ -226,6 +227,15 @@ static VALUE response_index_operator(VALUE self, VALUE index)
return rb_hash_aref(rb_ivar_get(self, __headers), index);
}

/*
* Exception
*/

static VALUE exception_message(VALUE self)
{
return rb_ivar_get(self, __message);
}

/*
* QAR
*/
Expand Down Expand Up @@ -316,6 +326,7 @@ static VALUE qar_find(int argc, VALUE *argv, VALUE self)
rb_eActiveResource##name, _allocate, 0); \
rb_ivar_set(e, __code, code); \
rb_ivar_set(e, __response, response); \
rb_ivar_set(e, __message, to_value(ex.message())); \
rb_exc_raise(e); \
}

Expand Down Expand Up @@ -363,7 +374,8 @@ extern "C"
DEFINE_CLASS(ActiveResource, Base);

#define AR_DEFINE_EXCEPTION(name, base) \
rb_eActiveResource##name = rb_define_class_under(rb_mActiveResource, #name, rb_e##base)
rb_eActiveResource##name = rb_define_class_under(rb_mActiveResource, #name, rb_e##base); \
rb_define_method(rb_eActiveResource##name, "message", (ARGS) exception_message, 0)

AR_DEFINE_EXCEPTION(ConnectionError, StandardError);
AR_DEFINE_EXCEPTION(TimeoutError, ActiveResourceConnectionError);
Expand Down

0 comments on commit af3c3ed

Please sign in to comment.