comparison src/c/urweb.c @ 1407:7d963b8019e6

Some fixes for tasks and onError handlers
author Adam Chlipala <adam@chlipala.net>
date Thu, 20 Jan 2011 15:11:45 -0500
parents 82b204f20026
children 56ba9c442a2d
comparison
equal deleted inserted replaced
1406:e8bea46f8eda 1407:7d963b8019e6
724 724
725 ctx->app->handle(ctx, path); 725 ctx->app->handle(ctx, path);
726 } 726 }
727 727
728 return r; 728 return r;
729 }
730
731 failure_kind uw_begin_onError(uw_context ctx, char *msg) {
732 int r = setjmp(ctx->jmp_buf);
733
734 if (ctx->app->on_error) {
735 if (r == 0) {
736 if (ctx->app->db_begin(ctx))
737 uw_error(ctx, BOUNDED_RETRY, "Error running SQL BEGIN");
738
739 ctx->app->on_error(ctx, msg);
740 }
741
742 return r;
743 } else
744 uw_error(ctx, FATAL, "Tried to run nonexistent onError handler");
745 } 729 }
746 730
747 uw_Basis_client uw_Basis_self(uw_context ctx) { 731 uw_Basis_client uw_Basis_self(uw_context ctx) {
748 if (ctx->client == NULL) 732 if (ctx->client == NULL)
749 uw_error(ctx, FATAL, "Call to Basis.self() from page that has only server-side code"); 733 uw_error(ctx, FATAL, "Call to Basis.self() from page that has only server-side code");
3745 return r; 3729 return r;
3746 } 3730 }
3747 else 3731 else
3748 return NULL; 3732 return NULL;
3749 } 3733 }
3734
3735 static const char begin_xhtml[] = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">";
3736
3737 failure_kind uw_begin_onError(uw_context ctx, char *msg) {
3738 int r = setjmp(ctx->jmp_buf);
3739
3740 if (ctx->app->on_error) {
3741 if (r == 0) {
3742 if (ctx->app->db_begin(ctx))
3743 uw_error(ctx, BOUNDED_RETRY, "Error running SQL BEGIN");
3744
3745 uw_write_header(ctx, "HTTP/1.1 500 Internal Server Error\r\n");
3746 uw_write_header(ctx, "Content-type: text/html\r\n\r\n");
3747 uw_write(ctx, begin_xhtml);
3748 ctx->app->on_error(ctx, msg);
3749 uw_write(ctx, "</html>");
3750 }
3751
3752 return r;
3753 } else
3754 uw_error(ctx, FATAL, "Tried to run nonexistent onError handler");
3755 }