@@ -11,6 +11,7 @@ import {
1111 MAX_EVENTS_PAGE_SIZE ,
1212} from "../routes/v1/events.routes.js" ;
1313import * as exportService from "../services/export.service.js" ;
14+ import { sendApiError } from "../types/api-error.js" ;
1415
1516/**
1617 * Public shape of a Stream, used when embedding streams inside a public
@@ -104,12 +105,10 @@ export const getUser = async (
104105 try {
105106 const { publicKey } = req . params ;
106107 if ( typeof publicKey !== "string" ) {
107- return res . status ( 400 ) . json ( { error : "Invalid publicKey parameter" } ) ;
108+ return sendApiError ( res , 400 , "INVALID_PUBLIC_KEY" , "Invalid publicKey parameter" ) ;
108109 }
109110 if ( ! STELLAR_PUBLIC_KEY_REGEX . test ( publicKey ) ) {
110- return res
111- . status ( 400 )
112- . json ( { error : "Invalid Stellar public key format" } ) ;
111+ return sendApiError ( res , 400 , "INVALID_PUBLIC_KEY" , "Invalid Stellar public key format" ) ;
113112 }
114113
115114 const user = await prisma . user . findUnique ( {
@@ -118,7 +117,7 @@ export const getUser = async (
118117 } ) ;
119118
120119 if ( ! user ) {
121- return res . status ( 404 ) . json ( { error : "User not found" } ) ;
120+ return sendApiError ( res , 404 , "NOT_FOUND" , "User not found" ) ;
122121 }
123122
124123 return res . status ( 200 ) . json ( user ) ;
@@ -138,12 +137,10 @@ export const getUserEvents = async (
138137 try {
139138 const { publicKey } = req . params ;
140139 if ( typeof publicKey !== "string" ) {
141- return res . status ( 400 ) . json ( { error : "Invalid publicKey parameter" } ) ;
140+ return sendApiError ( res , 400 , "INVALID_PUBLIC_KEY" , "Invalid publicKey parameter" ) ;
142141 }
143142 if ( ! STELLAR_PUBLIC_KEY_REGEX . test ( publicKey ) ) {
144- return res
145- . status ( 400 )
146- . json ( { error : "Invalid Stellar public key format" } ) ;
143+ return sendApiError ( res , 400 , "INVALID_PUBLIC_KEY" , "Invalid Stellar public key format" ) ;
147144 }
148145
149146 const rawLimit = req . query [ "limit" ] ;
@@ -255,7 +252,7 @@ export const exportTransactions = async (
255252 : addressParam ;
256253
257254 if ( ! address || ! STELLAR_PUBLIC_KEY_REGEX . test ( address ) ) {
258- return res . status ( 400 ) . json ( { error : "Invalid Stellar address" } ) ;
255+ return sendApiError ( res , 400 , "INVALID_ADDRESS" , "Invalid Stellar address" ) ;
259256 }
260257
261258 const format = ( req . query . format as string ) || "csv" ;
@@ -270,15 +267,11 @@ export const exportTransactions = async (
270267 const tokenAddress = ( req . query . tokenAddress as string | null ) || null ;
271268
272269 if ( ! [ "csv" , "json" ] . includes ( format ) ) {
273- return res
274- . status ( 400 )
275- . json ( { error : "Invalid format. Must be csv or json" } ) ;
270+ return sendApiError ( res , 400 , "INVALID_FORMAT" , "Invalid format. Must be csv or json" ) ;
276271 }
277272
278273 if ( ! [ "incoming" , "outgoing" , "all" ] . includes ( direction ) ) {
279- return res . status ( 400 ) . json ( {
280- error : "Invalid direction. Must be incoming, outgoing, or all" ,
281- } ) ;
274+ return sendApiError ( res , 400 , "INVALID_DIRECTION" , "Invalid direction. Must be incoming, outgoing, or all" ) ;
282275 }
283276
284277 const options : exportService . ExportOptions = {
0 commit comments