You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
15 lines
514 B
15 lines
514 B
6 years ago
|
import { QueryFailedError } from "typeorm";
|
||
|
|
||
|
import ApiError from "@common/ApiError";
|
||
|
import { ErrorCode } from "@common/ErrorCode";
|
||
|
|
||
|
export default class UniqueConstraintError extends ApiError {
|
||
|
static is(err: any): err is QueryFailedError {
|
||
|
return err && err.name === "QueryFailedError" && (err as any).code === 23505; // unique constraint error
|
||
|
}
|
||
|
|
||
|
constructor(err: QueryFailedError) {
|
||
|
super(`Unsatisfied unique constraint: ${(err as any).detail}`, ErrorCode.NotUnique, err);
|
||
|
}
|
||
|
}
|