Error response enhancements, CoreID auth client backend

This commit is contained in:
2022-03-29 01:14:46 -05:00
parent a039b1ff25
commit 8f08b94f74
31 changed files with 736 additions and 52 deletions

View File

@@ -2,7 +2,7 @@
* Base type for a canonical definition.
*/
import {Canon} from './Canon'
import {universalPath, UniversalPath, ErrorWithContext} from '../util'
import {universalPath, UniversalPath, ErrorWithContext, Safe} from '../util'
import {Logging} from './Logging'
import {Inject} from '../di'
import * as nodePath from 'path'
@@ -192,6 +192,18 @@ export abstract class Canonical<T> extends Unit {
return this.loadedItems[key]
}
/** Get a canonical item by key as a Safe value. */
public safe(key: string): Safe {
return (new Safe(this.get(key))).onError((message, value) => {
throw new ErrorWithContext(`Invalid canonical value: ${message}`, {
canonicalKey: key,
canonicalItems: this.canonicalItems,
value,
message,
})
})
}
/**
* Register a namespace resolver with the canonical unit.
*