Quantcast
Channel: ReScript Forum - Latest posts
Viewing all articles
Browse latest Browse all 2592

Creating bindings for a custom error type

$
0
0

Hello,

I’m trying to create some bindings for the following: https.HttpsError class  |  Cloud Functions for Firebase

I want to create a new object (of HttpsError) and raise it in a function.
So, I’m not quite sure how to describe that.

Next I also want to make this string enum to a type, https namespace  |  Cloud Functions for Firebase
Is that possible in ReScript?

So far I got:

    module HttpsError = {
      type functionsErrorCode =
        | @as("ok") Ok
        | @as("cancelled") Cancelled

      type t

      @module("firebase-functions/v2/https") @new
      external make: (~code: functionsErrorCode, ~message: string=?, ~data: {..}=?) => t = "HttpsError"

      external asException : t => Error.t = "%identity"
    }

// later usage
    if request.data == "error" {
      let ex = HttpsError.make(~code=HttpsError.Cancelled, ~message="Sending error from the server")->HttpsError.asException
      Error.raise(ex)
    }

Is that asException the way to go?


Viewing all articles
Browse latest Browse all 2592

Trending Articles