ouchdb angularJS http服务回调错误响应没有有用的信息

达里尔·瓦格纳(Darryl Wagoner)WA1GON

我正在尝试使用AngularJS http服务编写一些CouchDB TypeScript类。该呼叫可以顺利通过路径,但是我无法从服务器获取状态代码或json错误信息。当然,这是我真正需要提供给用户的信息。

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返回状态为“ 400错误的请求”

标头:

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)

身体有:

{
   "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."
}

谢谢你

达里尔·瓦格纳(Darryl Wagoner)WA1GON

经过大量的头部撞击后,我发现问题出在CORS。选项方法导致错误。不知道发生了什么,但这是另一天的问题。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章