1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

iOS firebase cloud functionsのcallで3840エラーが出たら

Posted at

#エラーが起きる時
###functions側(Typescript)

import * as functions from 'firebase-functions'

export const callTest = functions.region('asia-northeast1').https.onCall(data => {
  console.log('callTest called!')

  return {
    A: 'Hello World',
    B: 42
  }
})

###クライアント側

import Firebase

// ~省略~

func call() {
    Functions.functions().httpsCallable("callTest").call { (result, error) in
        if let result = result,
            let resData = result.data as? [String : Any] {
                print(resData)
                print("***成功だよ")
        }
            
        if let error = error {
            print(error)
            print("***エラーだよ")
        } else {
            print("***エラーはないよ")
        }
    }
}

###エラー

Error Domain = NSCocoaErrorDomain 
Code = 3840 
"JSON text did not start with array or object and option to allow fragments not set." 

#解決法
クライアント側でFunctions.functions()をするとき、呼び出したいfunctionがデプロイされているregionを指定する。

func call() {
    Functions.functions(region: "asia-northeast1").httpsCallable("callTest").call { (result, error) in
        // ~省略~
    }
}

原因はよくわからなかったので知っている方がいれば是非教えてください。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?