angularjs - couchdb angularJS http服务回调错误响应没有有用信息

标签 angularjs http service typescript couchdb

我正在尝试使用 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)

body 有:

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

谢谢

最佳答案

敲了一大堆头,发现问题出在CORS上。选项方法导致错误。不确定发生了什么,但这是另一天的问题。

关于angularjs - couchdb angularJS http服务回调错误响应没有有用信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36671694/

相关文章:

javascript - Angular.js 缓存 $compiled 模板/ng-repeat 中指令的渲染性能

javascript - Angularjs 使用的 Rails API

html - 我向 InMagic Textworks 系统发布的类似十六进制的内容是什么

jquery - 使用 jquery/python GAE 破坏 PUT 请求

java - 如何启动/停止/重新启动 Linux 服务以及如何从 Java 程序更新它们的配置文件

javascript - 如何将 $q 传递给 Angular Directive(指令)链接函数?

javascript - Angular-fullstack 获取当前用户 ID

javascript - Node .js `request.get` : store body in variable

linux - monit:无法识别的服务

grails - 如何避免导致 OutOfMemoryException 的巨大查询结果