本文整理匯總了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 }))