nebx_verdict 0.1.2 copy "nebx_verdict: ^0.1.2" to clipboard
nebx_verdict: ^0.1.2 copied to clipboard

Nebx Verdict is a result pattern to simplify error handling.

Nebx Verdict #

Pub License: MIT

Nebx Verdict is a result pattern to simplify error handling.

Get started #

Install #

Add the nebx_verdict package to your pubspec dependencies.

Examples #

Performing error handling :

class SomeRepository {
    IVerdict<SomeDataModel> getDataSuccess() {
        final result = successRemoteData();
        // you can fail fast here using guard clause
        
        // if using failedRemoteData(), then it's gonna returning ....
        // failed verdict with forbidden status / message
        if (result.isFailure) return Verdict.failed(result.issue);
        
        late final SomeDataModel model;
        
        try {
            model = SomeDataModel.fromJson(result.data);
        } catch (e) {
            return Verdict.failed(Issue.parsing());
        }
        
        // if the SomeDataModel.fromJson not throwing error
        // you will returning data with success
        return Verdict.successful(model);
    }
}

// pretending as a server returning JSON of SomeDataModel
IVerdict<SomeDataModel> successRemoteData() {
    final data = SomeDataModel(
        id: "492e1e70-597e-4f07-adc1-625fdd0efd71",
        name : "roselino",
        country_id : "ID"
    );
    
    // pretend as returning JSON from remote
    return Verdict.successful(data);
    }
    
IVerdict<SomeDataModel> failedRemoteData() {
    try {
       // ..... do something 
       // then pretend we got forbidden from error handling mapper
       // please check nebx package for easy dio error handling
       // https://pub.dev/packages/nebx/install
    } catch (e) {
        // then you will be returning with forbidden verdict
        return Verdict.failed(Issue.forbidden());
    }
    return Verdict.successful(data);
}
0
likes
135
points
47
downloads

Publisher

verified publishernebx.my.id

Weekly Downloads

Nebx Verdict is a result pattern to simplify error handling.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

equatable, flutter

More

Packages that depend on nebx_verdict