40 lines
1.6 KiB
TypeScript
40 lines
1.6 KiB
TypeScript
export declare enum codigosResposta {
|
|
sucesso = 200,
|
|
erroConhecido = 400,
|
|
erroPermissao = 401,
|
|
erroDesconhecido = 500
|
|
}
|
|
export type tipoRespostaSucesso<T> = {
|
|
cod: codigosResposta.sucesso;
|
|
valor: T;
|
|
mensagem: undefined;
|
|
eErro: false;
|
|
eCerto: true;
|
|
detalhes?: string[];
|
|
};
|
|
export type tipoRespostaErro = {
|
|
cod: codigosResposta.erroConhecido | codigosResposta.erroDesconhecido | codigosResposta.erroPermissao;
|
|
valor: undefined;
|
|
mensagem: string;
|
|
eErro: true;
|
|
eCerto: false;
|
|
detalhes?: string[];
|
|
};
|
|
export type tipoResposta<T> = tipoRespostaSucesso<T> | tipoRespostaErro;
|
|
export declare const gerarRespostas: <T>(registrarErroInterno: (erro: T) => Partial<tipoRespostaErro>) => {
|
|
valor: <T_1>(valor: T_1, detalhes?: string[]) => tipoRespostaSucesso<T_1>;
|
|
valorTrue: (detalhes?: string[]) => tipoRespostaSucesso<true>;
|
|
erro: (mensagem: string, detalhes?: string[]) => tipoRespostaErro;
|
|
erroPermissao: (mensagem?: string | undefined | null, detalhes?: string[]) => tipoRespostaErro;
|
|
erroInterno: (parametros: T, mensagem?: string) => tipoRespostaErro;
|
|
};
|
|
/**
|
|
* Uso de respostas em comuns
|
|
*/
|
|
export declare const respostaComuns: {
|
|
valor: <T>(valor: T, detalhes?: string[]) => tipoRespostaSucesso<T>;
|
|
valorTrue: (detalhes?: string[]) => tipoRespostaSucesso<true>;
|
|
erro: (mensagem: string, detalhes?: string[]) => tipoRespostaErro;
|
|
erroPermissao: (mensagem?: string | undefined | null, detalhes?: string[]) => tipoRespostaErro;
|
|
erroInterno: (parametros: unknown, mensagem?: string) => tipoRespostaErro;
|
|
};
|