Becklyn / mojave

A library of commonly used JavaScript tools and helpers by Becklyn
BSD 3-Clause "New" or "Revised" License
5 stars 3 forks source link

`request()` finalization #184

Closed apfelbox closed 5 years ago

apfelbox commented 5 years ago

This changes the behavior of request()

Success Case (Promise is resolved)

IF

Return Type

{ 
    response: Response,
    success: boolean, // true if status code is 2xx, false if 400
    data: /* payload */,
}

Failure Case: Request (Promise is rejected)

IF

Return Type

{ 
    error: Error,
    reason: "request_failed",
}

Failure Case: JSON (Promise is rejected)

IF

Return Type

{ 
    response: Response,
    error: Error,
    reason: "invalid_json",
}

Failure Case: Status Code (Promise is rejected)

IF

Return Type

{ 
    response: Response,
    data: any,
    reason: "status",
}