File tree Expand file tree Collapse file tree 1 file changed +17
-2
lines changed
Expand file tree Collapse file tree 1 file changed +17
-2
lines changed Original file line number Diff line number Diff line change 1+ import { config } from "dotenv" ;
2+ config ( ) ;
3+
14async function fetchData ( ) {
25 const dataType = "forecast" ;
36 let dataToSend = { } ;
@@ -25,16 +28,28 @@ async function fetchData() {
2528
2629 // FunctionsのAPIを叩く
2730 try {
28- const baseUrl = process . env . FUCTIONS_URL ;
31+ const jwtToken = process . env . JWT_TOKEN ;
32+ if ( ! jwtToken ) {
33+ console . error ( "JWT_TOKEN is not set" ) ;
34+ process . exit ( 1 ) ;
35+ }
36+ const baseUrl = process . env . FUNCTIONS_URL ;
37+ if ( ! baseUrl ) {
38+ console . error ( "FUCTIONS_URL is not set" ) ;
39+ process . exit ( 1 ) ;
40+ }
2941 const url = baseUrl + "/forecast" ;
3042 const res = await fetch ( url , {
3143 method : "POST" ,
3244 headers : {
3345 "Content-Type" : "application/json" ,
34- Auhtorization : `Bearer ${ process . env . JWT_TOKEN } ` ,
46+ Auhtorization : `Bearer ${ jwtToken } ` ,
3547 } ,
3648 body : JSON . stringify ( dataToSend ) ,
3749 } ) ;
50+ if ( ! res . ok ) {
51+ throw new Error ( `Failed to save data: ${ res . statusText } ` ) ;
52+ }
3853 console . log ( "successfully saved to Firestore:" , res ) ;
3954 } catch ( error ) {
4055 console . error ( "Error saving data:" , error ) ;
You can’t perform that action at this time.
0 commit comments