尽管操作成功,但在执行CRED操作后出现错误

时间:2019-04-10 10:07:42

标签: angular servlets

我正在编写一个Angular项目,并从我写了球衣的服务器上获取HTTP请求。

我已经准备了一个管理页面,可以通过该页面执行CRED操作。

当我执行一个动作时,我得到一个错误(好像操作失败了),并报告一条消息,说明操作成功。 我写的服务器上的某些内容可能导致了这种情况。

Angular服务器上的功能:

  public addCompany(newCompanyName:String, newCompanyPassword:String, newCompanyEmail:String ){
    let newP:any ={
      "name": newCompanyName,
      "password": newCompanyPassword,
      "email": newCompanyEmail,
      "coupons": []
      };

     this.myHttpClient.post<any>("http://localhost:8080/CouponSystemJersey/couponsystem/admin/insertCompany",newP).subscribe(
       (res)=>{console.log("new company")},
       (err)=>{console.log(err)}
       ); 
  }

服务器功能:

@POST
    @Path("insertCompany")
    @Consumes(MediaType.APPLICATION_JSON)
    public Response insertCompany(Company company) {
        try {
            getFacaed().insertCompany(company);
        } catch (CompanyAlreadyExistsException | SystemMalfunctionException e) {
            return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
        }
        return Response.ok("A new customer was inserted").build();
    }

错误消息:

HttpErrorResponse {headers: HttpHeaders, status: 200, statusText: "OK", url: "http://localhost:8080/CouponSystemJersey/couponsystem/admin/insertCompany", ok: false, …}
error:
error: SyntaxError: Unexpected token A in JSON at position 0 at JSON.parse (<anonymous>) at XMLHttpRequest.onLoad (http://localhost:4200/vendor.js:7932:51) at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (http://localhost:4200/polyfills.js:2781:31) at Object.onInvokeTask (http://localhost:4200/vendor.js:53413:33) at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (http://localhost:4200/polyfills.js:2780:60) at Zone.push../node_modules/zone.js/dist/zone.js.Zone.runTask (http://localhost:4200/polyfills.js:2553:47) at ZoneTask.push../node_modules/zone.js/dist/zone.js.ZoneTask.invokeTask [as invoke] (http://localhost:4200/polyfills.js:2856:34) at invokeTask (http://localhost:4200/polyfills.js:4102:14) at XMLHttpRequest.globalZoneAwareCallback (http://localhost:4200/polyfills.js:4139:21)
message: "Unexpected token A in JSON at position 0"
stack: "SyntaxError: Unexpected token A in JSON at position 0↵    at JSON.parse (<anonymous>)↵    at XMLHttpRequest.onLoad (http://localhost:4200/vendor.js:7932:51)↵    at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (http://localhost:4200/polyfills.js:2781:31)↵    at Object.onInvokeTask (http://localhost:4200/vendor.js:53413:33)↵    at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (http://localhost:4200/polyfills.js:2780:60)↵    at Zone.push../node_modules/zone.js/dist/zone.js.Zone.runTask (http://localhost:4200/polyfills.js:2553:47)↵    at ZoneTask.push../node_modules/zone.js/dist/zone.js.ZoneTask.invokeTask [as invoke] (http://localhost:4200/polyfills.js:2856:34)↵    at invokeTask (http://localhost:4200/polyfills.js:4102:14)↵    at XMLHttpRequest.globalZoneAwareCallback (http://localhost:4200/polyfills.js:4139:21)"
__proto__: Error
text: "A new customer was inserted"
__proto__: Object
headers: HttpHeaders
lazyInit: ƒ ()
lazyUpdate: null
normalizedNames: Map(0) {}
__proto__: Object
message: "Http failure during parsing for http://localhost:8080/CouponSystemJersey/couponsystem/admin/insertCompany"
name: "HttpErrorResponse"
ok: false
status: 200
statusText: "OK"
url: "http://localhost:8080/CouponSystemJersey/couponsystem/admin/insertCompany"
__proto__: HttpResponseBase

0 个答案:

没有答案