问题
I am developing a project under Firebase Hosting with Firebase Functions. Index.js:
exports.simpleFunction = functions.https.onCall((data, context) => {
return data;
});
Index.html:
var simpleFunction = firebase.functions().httpsCallable('simpleFunction');
simpleFunction("12").then (function(result) {
console.log(result);
}).catch(function(error) {
console.log("Error code:" + error.code);
});
In console I only get:
"Error code: Internal"
Could anybody help me figure out what happens?
回答1:
I reproduced your scenario on my project and your code works as expected, this is my HTML file
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Welcome to Firebase Hosting</title>
<script src="/__/firebase/8.0.0/firebase.js"></script>
<script src="/__/firebase/8.0.0/firebase-app.js"></script>
<script src="/__/firebase/8.0.0/firebase-functions.js"></script>
<script src="/__/firebase/init.js"></script>
<style media="screen">
</style>
</head>
<body>
Hello world!!
</body>
<script>html
let simpleFunction = firebase.functions().httpsCallable('simpleFunction');
simpleFunction("12").then(function (result) {
console.log(result);
}).catch(function (error) {
console.log("Error code:" + error.code);
});
</script>
</html>
I'm using latest firebase web packages and my function supports unauthenticated access.
Update I was able to reproduce this issue
I tried to invoke another function (python function) but since firebase-functions package doesn't exists on python, this looks the root cause, try to update your firebase-functions package or try with my reproduction example.
package.json
{
"name": "sample-http",
"version": "0.0.1",
"dependencies": {
"firebase-admin": "~9.2.0",
"firebase-functions": "^3.11.0"
}
}
function
const functions = require('firebase-functions');
exports.simpleFunction = functions.https.onCall((data, context) => {
return data;
});
来源:https://stackoverflow.com/questions/64560828/firebase-functions-throw-function-with-internal-error