gpt4 book ai didi

angular - 核心.js :6272 ERROR Error: Uncaught (in promise): HttpErrorResponse: {"headers": {"normalizedNames" SendGrid and Cloud Firestore

转载 作者:行者123 更新时间:2023-12-05 02:05:58 28 4
gpt4 key购买 nike

我使用了带有 Firebase 云功能的 SendGrid NodeJS 库。它工作正常,我可以发送电子邮件。但是在 Cloud 函数下方发生火灾后,它在 Ionic/Angular 客户端应用程序的控制台上显示以下错误。你知道为什么吗?

     core.js:6272 ERROR Error: Uncaught (in promise): 
HttpErrorResponse: {"headers":{"normalizedNames":
{},"lazyUpdate":null},"status":200,"statusText":"OK","url":"https://my-
app.cloudfunctions.net/sendEmail","ok":false,"name":"HttpErrorResponse","message"
:"Http failure during parsing for https://my-
app.cloudfunctions.net/sendEmail","error":{"error":{},"text":"success"}}
at resolvePromise (zone-evergreen.js:793)
at zone-evergreen.js:707
at SafeSubscriber._error (Observable.js:91)
at SafeSubscriber.__tryOrUnsub (Subscriber.js:183)
at SafeSubscriber.error (Subscriber.js:135)
at Subscriber._error (Subscriber.js:75)
at Subscriber.error (Subscriber.js:55)
at MapSubscriber._error (Subscriber.js:75)
at MapSubscriber.error (Subscriber.js:55)
at FilterSubscriber._error (Subscriber.js:75)

package.json

{
"name": "functions",
"scripts": {
"lint": "tslint --project tsconfig.json",
"build": "tsc",
"serve": "npm run build && firebase emulators:start --only functions",
"shell": "npm run build && firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"engines": {
"node": "10"
},
"main": "lib/index.js",
"dependencies": {
"@sendgrid/mail": "^7.2.1",
"@types/cors": "^2.8.6",
"axios": "^0.19.2",
"cors": "^2.8.5",
"firebase-admin": "^8.10.0",
"firebase-functions": "^3.6.1"
},
"devDependencies": {
"tslint": "^5.12.0",
"typescript": "^3.8.0",
"firebase-functions-test": "^0.2.0"
},
"private": true
}

云函数

import * as functions from 'firebase-functions';
import * as sgMail from '@sendgrid/mail';
import * as cors from 'cors';

const corsHandler = cors({ origin: true });

export const sendEmail = functions.https.onRequest((request, response) => {

return corsHandler(request, response, async () => {

const apiKey = functions.config().sendgrid.key;
const emailTemplateId = functions.config().sendgrid.template;

sgMail.setApiKey(apiKey);

const email = {
templateId: emailTemplateId,
from: 'me@y.com',
to: 'me@y.com',
dynamic_template_data: {
firstName: request.body.firstName,
lastName: request.body.lastName,
},
};

try {
await sgMail.send(email);
response.send('success');

} catch (err) {
console.log("Send Email request failure", err);
response.send('failure');
}
});
});

客户端应用的服务

import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { environment } from 'src/environments/environment';
import { SellMyHouseModel } from 'src/app/models/sell-my-house.model';

@Injectable({
providedIn: 'root'
})
export class SendEmailService {

constructor(private httpClint: HttpClient) { }

sendEmail(sellMyHouse: SellMyHouseModel): Promise<any> {
return this.httpClint.post(environment.cloudFunctionUrl + 'sendEmail', sellMyHouse, this.createHeader('application/json')).toPromise();
}

private createHeader(contentType: string): any {
return { headers: new HttpHeaders({ 'Content-Type': contentType }) };
}

}

最佳答案

我已经这样做了,不再有上述问题。即 responseType: 'text'

 private createHeader(contentType: string): any {
return { headers: new HttpHeaders({ 'Content-Type': contentType }), responseType: 'text' };
}

关于angular - 核心.js :6272 ERROR Error: Uncaught (in promise): HttpErrorResponse: {"headers": {"normalizedNames" SendGrid and Cloud Firestore,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63061582/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com