@@ -329,7 +329,7 @@ finalize_err_cb(PyObject *awaitable, PyObject *result)
329329 PyObject * raw_path ;
330330 const char * method_str ;
331331 route * r ;
332- int is_http ;
332+ long is_http ;
333333
334334 if (
335335 PyAwaitable_UnpackValues (
@@ -767,75 +767,78 @@ route_error(
767767 )
768768 return -1 ;
769769
770- int is_http ;
770+ long is_http ;
771771
772772 if (PyAwaitable_UnpackIntValues (awaitable , & is_http ) < 0 )
773773 return -1 ;
774774
775- if (PyErr_GivenExceptionMatches (err , self -> error_type ))
776- {
777- PyObject * status_obj = PyObject_GetAttrString (
778- err ,
779- "status"
780- );
781- if (!status_obj )
782- return -2 ;
775+ if (self -> error_type != NULL )
776+ // Under general cirumstances, error_type should never
777+ // be NULL. But, we might as well support it.
778+ if (PyErr_GivenExceptionMatches (err , self -> error_type ))
779+ {
780+ PyObject * status_obj = PyObject_GetAttrString (
781+ err ,
782+ "status"
783+ );
784+ if (!status_obj )
785+ return -2 ;
783786
784- PyObject * msg_obj = PyObject_GetAttrString (
785- err ,
786- "message"
787- );
787+ PyObject * msg_obj = PyObject_GetAttrString (
788+ err ,
789+ "message"
790+ );
788791
789- if (!msg_obj )
790- {
791- Py_DECREF (status_obj );
792- return -2 ;
793- }
792+ if (!msg_obj )
793+ {
794+ Py_DECREF (status_obj );
795+ return -2 ;
796+ }
794797
795- int status = PyLong_AsLong (status_obj );
796- if ((status == -1 ) && PyErr_Occurred ())
797- {
798- Py_DECREF (status_obj );
799- Py_DECREF (msg_obj );
800- return -2 ;
801- }
798+ int status = PyLong_AsLong (status_obj );
799+ if ((status == -1 ) && PyErr_Occurred ())
800+ {
801+ Py_DECREF (status_obj );
802+ Py_DECREF (msg_obj );
803+ return -2 ;
804+ }
802805
803- const char * message = NULL ;
806+ const char * message = NULL ;
804807
805- if (msg_obj != Py_None )
806- {
807- message = PyUnicode_AsUTF8 (msg_obj );
808- if (!message )
808+ if (msg_obj != Py_None )
809+ {
810+ message = PyUnicode_AsUTF8 (msg_obj );
811+ if (!message )
812+ {
813+ Py_DECREF (status_obj );
814+ Py_DECREF (msg_obj );
815+ return -2 ;
816+ }
817+ }
818+
819+ if (
820+ fire_error (
821+ self ,
822+ awaitable ,
823+ status ,
824+ r ,
825+ NULL ,
826+ message ,
827+ method_str ,
828+ is_http
829+ ) < 0
830+ )
809831 {
810832 Py_DECREF (status_obj );
811833 Py_DECREF (msg_obj );
812834 return -2 ;
813835 }
814- }
815836
816- if (
817- fire_error (
818- self ,
819- awaitable ,
820- status ,
821- r ,
822- NULL ,
823- message ,
824- method_str ,
825- is_http
826- ) < 0
827- )
828- {
829837 Py_DECREF (status_obj );
830838 Py_DECREF (msg_obj );
831- return -2 ;
839+ return 0 ;
832840 }
833841
834- Py_DECREF (status_obj );
835- Py_DECREF (msg_obj );
836- return 0 ;
837- }
838-
839842 if (!is_http )
840843 {
841844 // send a websocket error code
0 commit comments