File size: 561 Bytes
d76f93d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

export interface ErrorResponse {
    message: string;
    code?: string;
    statusCode?: number;
  }
  
  export interface ApiResponse<T> {
    data?: T;
    successful: boolean;
    error?: ErrorResponse;
  }
  
  export function wrapResponse<T>(data?: T): ApiResponse<T> {
    return { data, successful: true };
  }
  
  export function wrapError<T>(
    message: string,
    statusCode: number = 500,
    code?: string
  ): ApiResponse<T> {
    return {
      data: undefined,
      successful: false,
      error: { message, statusCode, code },
    };
  }