Darryl Wagoner WA1GON
Darryl Wagoner WA1GON

Reputation: 1029

couchdb angularJS http service callback error response has no useful information

I am trying to write some CouchDB TypeScript classes using AngularJS http service. The call works fine for happy path, however I am unable to get status code or json error information back from the server. Of course this is the information that I really need to give to the user.

public createDb(name: string, callback: Function) {
    let url = this.urlPrefix + name;
    let cbData: CouchStatus = new CouchStatus;

    this.http.put(url).then((response: any) => {

        cbData.httpStatus = response.status;
        if (response.data.ok === true) {
            cbData.ok = true;
        } else {
            cbData.ok = false;
            cbData.error = response.data.error;
            cbData.reason = response.data.reason;
        }
        callback(cbData);
    }, (httpError: any) => {

        cbData.ok = false;
        cbData.httpStatus = httpError.status;
        cbData.error = httpError.data;
        console.log("createDb: " + cbData.error);
    });
}

Couchdb returns a Status of "400 bad Request"

Headers:

Access-Control-Allow-Origin → chrome-extension://fdmmgilgnpjigdojojpjoooidkmcomcm
Access-Control-Expose-Headers → Cache-Control, Content-Type, Server
Cache-Control → must-revalidate
Content-Length → 197
Content-Type → text/plain; charset=utf-8
Date → Sun, 17 Apr 2016 01:15:49 GMT
Server → CouchDB/1.6.1 (Erlang OTP/R16B02)

The body has:

{
   "error":"illegal_database_name",
   "reason":"Name: 'fooBar'. Only lowercase characters (a-z), digits (0-9), 
    and any of the characters _, $, (, ), +, -, and / are allowed. Must begin
    with a letter."
}

thank you

Upvotes: 1

Views: 82

Answers (1)

Darryl Wagoner WA1GON
Darryl Wagoner WA1GON

Reputation: 1029

After a lot of head banging, I found that the problem was CORS. Option method was causing an error. Not sure what is going on, but that is a problem for another day.

Upvotes: 1

Related Questions