从承诺中获得“数据”价值

时间:2018-08-13 20:01:31

标签: javascript promise

我有以下代码:

{
    "timestamp": "2018-08-13T19:18:47.246+0000",
    "status": 415,
    "error": "Unsupported Media Type",
    "message": "Content type 'multipart/form-data;boundary=--------------------------175574471409780768513459;charset=UTF-8' not supported",
    "path": "/alian"
}

输出以下Promise: enter image description here

此Promise中唯一需要的信息是“数据”行: enter image description here

要获得该值我需要打印什么?

3 个答案:

答案 0 :(得分:1)

好像 getMovies(): Observable<Movie[]> { return this.http.get<Movie[]>(this.moviesUrl) .pipe( tap(data => console.log(JSON.stringify(data))), catchError(this.handleError) ); } 返回了一个承诺,那么您可以执行以下操作:

repo.getBlob(sha)

或者您可以尝试

repo.getBlob(sha).then(data=> console.log(data))

答案 1 :(得分:0)

您可能必须这样做:

let blob = repo.getBlob(sha, function (error, data) {
    console.log("===== BLOB =====");
    console.log(data);
});

或者您可以尝试以下操作:

repo.getBlob(sha).then(function (data) {
    console.log(data);
});

答案 2 :(得分:0)

好像您正在使用nodegit库。

因此,根据nodegit API documentation,您必须以这种方式调用getBlob方法:

repository.getBlob(String).then(function(blob) {
  // Use blob
});

祝你好运!