本文整理汇总了TypeScript中space-lift.Err函数的典型用法代码示例。如果您正苦于以下问题:TypeScript Err函数的具体用法?TypeScript Err怎么用?TypeScript Err使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Err函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: catch
xhr.onreadystatechange = () => {
if (xhr.readyState !== 4) return
// IE can throw an error when accessing the status
let status = 0
try { status = xhr.status }
catch (e) {}
if (status === 0)
return resolve(Err<AjaxError>({ type: 'networkError' }))
if (!isOkStatus(status))
return resolve(Err<AjaxError>({ type: 'badResponse', code: status, response: xhr.responseText }))
let responseBody
try { responseBody = JSON.parse(xhr.responseText) }
catch (e) { return resolve(Err<AjaxError>({
type: 'badPayload',
payload: xhr.responseText,
validationErrors: []
})) }
const validated = validator.validate(responseBody)
if (validated.isOk())
resolve(validated as Ok<never, V>)
else
resolve(Err<AjaxError>({
type: 'badPayload',
payload: responseBody,
validationErrors: validated.get()
}))
}
示例2: Err
.then((response: Instagram.Response) => {
if (response.meta.code === 400) {
return Err({
message: response.meta.error_message,
info: `URL: ${url}`,
})
}
cache.set(key, response.data, 22)
return Ok(response.data)
})
示例3: function
xhr.abort = function() {
xhr.onreadystatechange = null!
abortXhr()
resolve(Err<AjaxError>({ type: 'aborted' }))
}
示例4:
.catch(error => Err<AjaxError>({ type: 'technicalError', error }))