742efb6ff310c75a30cf13088111139cf713b9db angie Tue Feb 23 11:06:52 2016 -0800 Unifying some triplicate code to print an HTTP error 400 response (Bad Request) and exit. diff --git src/hg/hgSuggest/hgSuggest.c src/hg/hgSuggest/hgSuggest.c index 7b7ccf4..e6114ee 100644 --- src/hg/hgSuggest/hgSuggest.c +++ src/hg/hgSuggest/hgSuggest.c @@ -1,63 +1,60 @@ /* hgGeneSuggest - suggest a gene. */ /* Copyright (C) 2013 The Regents of the University of California * See README in this or parent directory for licensing information. */ #include "common.h" #include "jksql.h" #include "hdb.h" #include "cheapcgi.h" +#include "htmshell.h" #include "dystring.h" #include "jsonParse.h" #include "suggest.h" #include "genbank.h" -static void fail(char *msg) -{ -puts("Status: 400\n\n"); -puts(msg); -exit(-1); -} int main(int argc, char *argv[]) { long enteredMainTime = clock1000(); cgiSpoof(&argc, argv); char *prefix = cgiOptionalString("prefix"); char *database = cgiOptionalString("db"); initGenbankTableNames(database); int exact = cgiOptionalInt("exact", 0); struct sqlConnection *conn; char query[2048]; char **row; struct sqlResult *sr; int count = 0; boolean hasKnownCanonical; struct dyString *str = newDyString(10000); char *table; +pushAbortHandler(htmlVaBadRequestAbort); if(prefix == NULL || database == NULL) - fail("Missing prefix or database parameter"); + errAbort("%s", "Missing prefix and/or db CGI parameter"); conn = hAllocConn(database); table = connGeneSuggestTable(conn); if(table == NULL) - fail("gene autosuggest is not supported for this assembly"); + errAbort("gene autosuggest is not supported for db '%s'", database); +popAbortHandler(); hasKnownCanonical = sameString(table, "knownCanonical"); puts("Content-Type:text/plain"); puts("\n"); dyStringPrintf(str, "[\n"); if(exact) { // NOTE that exact is no longer used by the UI as of v271, but there are still some robots using it so we still support it. if(hasKnownCanonical) sqlSafef(query, sizeof(query), "select x.geneSymbol, k.chrom, kg.txStart, kg.txEnd, x.kgID, x.description " "from knownCanonical k, knownGene kg, kgXref x where k.transcript = x.kgID and k.transcript = kg.name " "and x.geneSymbol = '%s' order by x.geneSymbol, k.chrom, kg.txEnd - kg.txStart desc", prefix);