 "use strict"
 
-if global.bootbox?.alert?
+global.bootbox.CancellationError or= class CancellationError
+  constructor: (message) ->
+    return new CancellationError(message) unless this instanceof CancellationError
+    message = "operation cancelled" unless typeof(message) == "string"
+    Object.defineProperty(this, "message", value: message)
+    Object.defineProperty(this, "name", value: "CancellationError")
+    if Error.captureStackTrace?
+      Error.captureStackTrace(this, @constructor)
+    else
+      Error.call(this)
+    return
+
+if global.bootbox.alert?
   global.bootbox.alert_p = (arg) ->
     return new Promise((resolve) ->
       opt = {}

      global.bootbox.alert(opt)
    )

if global.bootbox?.confirm?
  global.bootbox.confirm_p = (arg) ->
    return new Promise((resolve, reject) ->
      opt = {}

        (opt[k] = v) for k, v of arg
      opt.callback = (result) ->
        return resolve() if result
        return reject(new global.bootbox.CancellationError())
      global.bootbox.confirm(opt)
    )

if global.bootbox.prompt?
  global.bootbox.prompt_p = (arg) ->
    return new Promise((resolve, reject) ->
      opt = {}
