js2ts: util.ts 분리
This commit is contained in:
+1
-1
@@ -7,7 +7,7 @@ import { DATE_TIME_FORMAT, getDateTimeNow } from "../hwe/ts/util/getDateTimeNow"
|
||||
import { sha512 } from "js-sha512";
|
||||
import { convertFormData } from "../hwe/ts/util/convertFormData";
|
||||
import { InvalidResponse } from "../hwe/ts/defs";
|
||||
import { unwrap } from "./util";
|
||||
import { unwrap } from "../hwe/ts/util/unwrap";
|
||||
|
||||
type ResultUserInfo = {
|
||||
result: true,
|
||||
|
||||
-35
@@ -1,35 +0,0 @@
|
||||
type ErrType<T> = { new(msg?: string): T }
|
||||
type Nullable<T> = T | null | undefined
|
||||
|
||||
export class RuntimeError extends Error {
|
||||
public name = 'RuntimeError';
|
||||
constructor(public message: string = '') {
|
||||
super(message);
|
||||
}
|
||||
toString(): string {
|
||||
if (this.message) {
|
||||
return this.name + ': ' + this.message;
|
||||
}
|
||||
else {
|
||||
return this.name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class NotNullExpected extends RuntimeError {
|
||||
public name = 'NotNullExpected';
|
||||
}
|
||||
|
||||
export function unwrap<T>(result: Nullable<T>): T {
|
||||
if (result === null || result === undefined) {
|
||||
throw new NotNullExpected();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
export function unwrap_err<T, ErrT extends Error>(result: Nullable<T>, errType: ErrType<ErrT>, errMsg?: string): T {
|
||||
if (result === null || result === undefined) {
|
||||
throw new errType(errMsg);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
Reference in New Issue
Block a user